C함수 버퍼 내용을 디스크로 쓰기 fsync()
파일로 아직 쓰기가 되지 않은 메모리의 내용을 모두 쓰기가 되도록 합니다. sync()가 모든 메모리에 대해서라면 fsync()는 지정된 파일 디스크립터에 대해 진행합니다.
- 헤더: unistd.h
- 형태: int fsync (int fd)
- 인수: int fd 파일 디스크립터
- 반환: int 0 == 성공, -1 == 실패
C언어 fsync() 함수 예제
#include <stdio.h>
#include <string.h> // strlen()
#include <fcntl.h> // open()
#include <unistd.h> // sync()
int main()
{
int fd;
char *str = "https://badayak.com";
fd = open( "test.txt", O_WRONLY ¦ O_CREAT, 0644);
write( fd, str, strlen( str));
if ( -1 == fsync( fd)) // 버퍼의 내용을 모두 쓰기를 합니다.
printf( "fsync() 실패\n");
close( fd);
}
'컴퓨터 > 프로그래밍' 카테고리의 다른 글
C언어 프로세스 생성 함수 vfork() (0) | 2020.03.15 |
---|---|
C언어 버퍼 내용을 디스크로 쓰기 함수 sync() (0) | 2020.03.15 |
C언어 루트 디렉토리 지정 함수 chroot() (0) | 2020.03.15 |