보조 기억 장치 할당의 최소 단위
Sequence of bytes(물리적 정의)
OS는 file operation들에 대한 system call을 제공해야함
#include <sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
int open (const char *pathname, int flags [,mode_t mode]);
#include <unistd.h>
int close (int fd);
fd : 닫으려는 file descriptor
return 0 : success -1 : error
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main(){
int fd; // 파일 디스크립터 저장
mode_t mode; // 모드t 변수타입 사용
mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
fd = open("hello.txt",O_CREAT, mode); //644
if (fd == -1){
perror("Creat"); exit(1);
} // 파일이름,access, 모드
close(fd);
return 0;
}
O_EXCL 사용해보기
int main(void){
int fd;
fd= open("hello.txt", O_CREAT|O_EXCL,0644);
if(fd == -1){
perror("EXCL");
exit(1);
}
close(fd);
return 0;
}