mkdir
명령어를 사용해 디렉토리를 만들어줌.cd
명령어를 이용하여 aa 디렉토리로 이동한 후, bb 파일을 만듦./aa/bb(aa 디렉토리에 위치하는 bb라는 이름의 파일)을 open하고 x로부터 10byte를 읽어옴.
open 이후의 fd x의 f_pos는 0이어서, 첫번째 cd r printf는 첫 10byte가 됨.
이후, lseek 함수를 호출하는 데, fd x의 f_pos가 10에서 20으로 바뀌고, f_pos=20부터 10byte를 읽게 됨.
두번째 printf는 11에서 20에 해당하는 것을 건너뛰고 출력하게 되는 것.
→ qwertyuio를 건너뛰고 출력한 셈!
이후로, x1=dup(x)가 호출됨.
이때, dup(x)는 fd x를 복제하는 함수로, 작은 fd부터 탐색하면서 빈 fd를 찾은 뒤에 이 값을 복사하게 됨.
→ 이 함수의 호출로 x1도 x와 같은 파일 구조체를 가리키게 되고, f_pos의 값도 공유하게 됨.
fd x의 f_pos는 마지막 출력을 하고난 후, 30의 값을 저장하고 있음.
fd x에 read를 수행할 때, 그 뒤의 10byte를 읽고 출력하게 됨.
link 함수는 파일을 생성하고 해당 파일에게 같은 inode number를 부여함.
→ 이는 파일 이름만 다른, 같은 파일을 의미함.
link(”/aa/bb”,”aa/newbb”)를 부여받음.
→ /aa/newbb는 /aa/bb와 같은 파일이므로 /aa/bb의 첫 10byte를 출력하게 됨.
# ls –i /aa/*