강의자료(0924)

Download Report

Transcript 강의자료(0924)

시스템 호출
• 파일의 끝에 자료 추가 – p37
lseek(fd, (off_t)0, SEEK_END);
write(fd, buf, BUFSIZE);
fd = open(“filename”, O_WRONLY | O_APPEND, 0644);
write(fd, buf, BUFSIZE);
• 파일의 제거 – test1.c
int unlink(const char *pathname);
int remove(const char *pathname);
- 성공시 0, 실패시 -1을 반환
- rm과 동일
시스템 호출
• fcntl
– int fcntl(int filedes, int cmd, …);
– F_SETFL, F_GETFL
•
•
fcntl (filedes, F_GETFL);
fcntl(filedes, F_SETFL, O_APPEND);
– 읽기 전용으로 개방된 파일을 읽기 쓰기용으로 개방된 파일로 변경 불가능
– test2.c
표준 입출력
•
•
표준입력 (0), 표준출력(1), 표준오류(2)
Redirection < >
–
–
•
pipe
–
•
prog1|prog2
(p42) IO test
–
•
prog_name < infile
prog_name > outfile
test3.c
실습 – 연습문제 2.15
표준 입출력
•
표준 I/O 라이브러리
–
–
•
fprintf, perror
–
•
make > log.out 2 > log.err
test5.c
fprintf (stderr, “error number %d\n”, errno);
실습 – test5.c 를 시스템 호출 프로그램으로 변환하라.