Information Technology Reference
In-Depth Information
Exercises
For convenience, the exercises from the body of the chapter are repeated here.
1. Discussion Suppose a process successfully opens an existing file that has
a single hard link to it, but while the process is reading that file, another
process unlinks that file. What should happen to subsequent reads by the
first process? Should they succeed? Should they fail? Why?
2. In Linux, suppose a process successfully opens an existing file that has a
single hard link to it, but while the process is reading that file, another
process unlinks that file? What happens to subsequent reads by the first
process? Do they succeed? Do they fail? (Answer this problem by con-
sulting documentation or by writing a program to test the behavior of the
system in this case.)
3. Write a program that creates a new file, writes 100KB to it, flushes the
writes, and deletes it. Time how long each of these steps takes.
Hint You may find the Posix system calls creat() , fwrite(), , fflush() ,
fclose()) , and gettimeofday() useful. See the maual pages for details on
how to use these.
4. Consider a text editor that saves a file whenever you click a save button.
Suppose that when you press the button, the editor simply (1) animates
the button \down" event (e.g., by coloring the button grey), (2) uses the
fwrite(), system call to write your text to your file, and then (3) animates
the button \up" event (e.g., by coloring the button white). What bad
thing could happen if a user edits a file, saves it, and then turns off her
machine by flipping the power switch (rather than shutting the machine
down cleanly)?
5. Write a program that times how long it takes to issue 100,000 one-byte
writes in each of two ways. First, time how long it takes to use the Posix
system calls creat() , fwrite(), , and fclose()) directly. Then see how long
these writes take if the program uses the stdio library calls (e.g., fopen() ,
fwrite() , and fclose() ) instead. Explain your results.
Search WWH ::




Custom Search