시스템프로그래밍 Lecture6. File system call
- 최초 등록일
- 2015.01.04
- 최종 저작일
- 2013.04
- 11페이지/ 한컴오피스
- 가격 1,000원
소개글
수정할 곳 없는 정말 완벽한 보고서입니다.
보고서 쓰시는데 도움이 되었으면 좋겠습니다.
목차
Lecture6 : File system call
0) Try the code in 6-1) and 6-2). You need to make f1 and fill it with more than 20 bytes.
1) Use vi to make a file “f2” as below. Find the byte size of f2 with “ls –l f2”. Use xxd to find out the actual data stored in f2.
2) Write a program "hw9-2.c" that opens f2 and shows each byte of it in hexa, decimal, and character.
3) Compile the code in 9-2) with –g option and run gdb to execute each instruction one by one. Use “p” or “x” to check the value of a variable.
4) Write a program that creates a file and writes “hello there”in it. Use open() and write(). Confirm the result with "cat".
5) Write a program that makes a copy for file "hw9-2.c" into another file "cphw9-2.c". Use open(), read(),and write(). Confirm that they are same with "cat" and "ls –l".
6) Write a program that makes a copy for file "hw9-2" (the executable file for "hw9-2.c) into another file cphw9-2. Confirm that they are same with "xxd" and "ls -l". Execute cphw9-2 to see if it runs ok.
7) Repeat 5). But get the name of the files from the user.
본문내용
먼저 vi인 텍스트에디터를 이용하여 다음과 같이 ex6_1.c를 작성한다.
소스파일을 컴파일하고 실행하면 다음과 같이 20bytes만 출력됨을 볼 수 있다. 이는 f1파일의 내용 중 앞부분 20bytes만을 읽고 출력한 후 종료한다는 것을 알 수 있다.
두 번째로 vi인 텍스트에디터를 이용하여 다음과 같이 ex6_2.c를 작성한다.
소스파일을 컴파일하고 실행하면 다음과 같이 모든 내용이 출력됨을 볼 수 있다. 이는 위와 비슷하지만 f1파일의 모든 내용을 출력한 후 종료한다는 것을 알 수 있다.
<중 략>
- 프로그램 실행 명령어: r (run) r 명령을 내림으로써 실제로 디버깅에 들어간다.
- 명령어 : n (next) 현재 행 수행 후 정지, 함수 호출 시 함수 수행 후 다음 행으로 간다.
- 브레이크 포인트 명령어 b (break) 문제가 발생한 부분에 브레이크를 걸어서 r 명령으로 프로그램을 수행할 때, 브레이크를 건 부분에서 프로그램이 멈추는 것을 확인할 수 있다. 브레이크는 특정 라인이나 함수에 걸 수 있다.
- 명령어 : p 현재 변수에 저장되어 있는 값을 보여준다. *를 이용하여 포인터 값을 볼 수도 있다.
- (gdb) 16xb buf : x명령어는 현재 메모리의 값을 보여주는 명령어인데 / 이하는 옵션을 나타낸다. 바로 뒤에 나오는 숫자는 보여줄 메모리의 개수를 의미하며 그 다음 알파벳은 순서대로 16진수로 출력, 10바이트를 한 단위의 메모리로 생각한다는 것이다.
<중 략>
x에는 원본 파일 hw9-2.c를 open하고 x2에는 복사파일인 cphw9-2를 새로 open한다. y로 20bytes씩 read하여 z에 write하여 복사를 실행한다.
소스파일을 컴파일하고 실행하면 다음과 같이 출력됨을 볼 수 있다. ls 명령어만 사용하였을 때에는 hw9-2와 cphw9-2가 모두 보이지 않아 ls –l 명령어를 사용하여 출력하였다.
참고 자료
없음