Input : I/O system에서 main memory로

Output: main memory 에서 I/O system으로

I/O는 프로세스의 생성과 실행과정에서 서로 다른 프로세스들이 어떻게 파일을 공유하는가에 대해 핵심 역할을 수행한다.

리눅스에서 파일은 연속된 m개의 바이트다.

Text file : ASCII 문자나 유니코드로 이루어진 파일

그 외 모든 파일 : 이진파일

int open(char *filename, int flags, mode_t mode);
			// Returns: new file descriptor if OK, −1 on error

/*
flags argument
O_RDONLY. Reading only
O_WRONLY. Writing only
O_RDWR. Reading and writing

additional flags argument
O_CREAT. If the file doesn’t exist, then create a truncated (empty) version.
O_TRUNC. If the file already exists, then truncate it.
O_APPEND. Before each write operation, set the file position to the end of
the file.
*/
fd = Open("foo.txt", O_WRONLY|O_APPEND, 0);

int close(int fd); //Returns: 0 if OK, −1 on error
ssize_t read(int fd, void *buf, size_t n);
// Returns: number of bytes read if OK, 0 on EOF, −1 on error
ssize_t write(int fd, const void *buf, size_t n);
// Returns: number of bytes written if OK, −1 on error

read : 식별자 fd의 현재 파일 위치에서 최대 n byte를 메모리 위치 buf로 복사

write: 메모리 위치 buf에서식별자 fd의 현재 파일 위치로 최대 n byte 복사


Robust Reading and Writing with RIO package