cat2.c 프로그램을 strace로 조사해보자.
stdio 버퍼링 확인)
dev@dev-desktop:~/codeexample$ strace -e trace=open,read,write,close ./cat data >/dev/null
close(3) = 0
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200l\2\0\0\0\0\0"..., 832) = 832
close(3) = 0
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 2048
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 2048) = 1418
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 1418) = 1418
read(3, "", 2048) = 0
close(3) = 0
+++ exited with 0 +++
dev@dev-desktop:~/codeexample$ strace -e trace=open,read,write,close ./cat2 data >/dev/null
close(3) = 0
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200l\2\0\0\0\0\0"..., 832) = 832
close(3) = 0
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
read(3, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 1418
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 4096) = 4096
read(3, "", 4096) = 0
close(3) = 0
write(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"..., 1418) = 1418
+++ exited with 0 +++
같은 aaa로 도배된 파일이지만 버퍼링때문에 읽기와 쓰기 횟수가 다르다.
반응형
'OS > 리눅스 기초' 카테고리의 다른 글
8. stdio로 cat 명령어 만들어보기 (0) | 2019.10.10 |
---|---|
6. 스트림 관련 라이브러리 함수(stdio)-1 (0) | 2019.10.10 |
1. gcc로 컴파일하기 & 커맨드라인 인자 (0) | 2019.10.02 |
책소개 (0) | 2019.10.02 |