Designed by Junyi Yang([email protected])
In this lab, we'll know some functions available for file I/O. We only list the names of the functions which you may need, in order to make you know how to use the UNIX manuals and the search engine.
Be Clear that you only need to know how to use them when you really need to do so.(In our TODO, for example) Now you only need to know what they can do.
- open
- creat
- close
- lseek
- read
- write
- sync
- dup, dup2
Followings are some useful website. Your UNIX system manual is also useful.
Usually, you need to seek help from those websites in English.
- Write a program that opens a file using
open()
system call and then callsfork()
to create a new process. What happens to the file's offset in parent process when you change the file's offset in child process? Explain it.- You can use
write
orlseek
to change the file's offset. - You may use
lseek
to view current offset. - You may use
wait
to guarantee synchronization, which means letting child process change the file's offset first.
- You can use
- Write a program that creates a child process, and connects the standard output of parent process to the standard input of child process. Write some messages to the standard output in the parent process, and read them in the child process. Followings are the functions you may need.
- dup2
- pipe
- read
- write
- Write a program that creates two children, and connects the standard output of one to the standard input of the other.
- UNIX system manuals
- W. Richard Stevens, Stephen A. Rago. Advanced Programming in the Unix Environment, Third Edition. Person Education, Inc.. 2013
- Operating System: Three Easy Pieces