CS360 Final Exam: December 12, 2000. Question 1: Answers/Grading

For parts i-iii, suppose f1 is a three line file. This means that sort works and sends the three lines to head, which simply echos them to cat. This means that:

For parts iv-vi, suppose f1 is a 100,000 line file. Now, sort will read all of its input. When read() returns zero, it sorts the output and tries to send it all to standard output. However, after the 5th line, head exits, meaning there is no read end to the pipe. Therefore sort receives SIGPIPE. Cat works as before.

For parts vii-ix, suppose f1 does not exist. Now, the shell is still going to fork all of its processes. However, the sort process is going to fail when trying to open f1, and it will exit before ever calling execvp (see the answer to question 5). The head process won't get any input -- read() will return zero. Ditto for cat.

For parts x-xii, suppose the program cat does not exist, and f1 is a one line file. Now the execvp() call is going to fail for cat. However, the head process won't know that cat is dead until it tries to write its first line of output. At that point, it catches SIGPIPE. Since it does this after reading the first line of input, the sort process works fine -- it writes its line of input to head and exits. If f1 had more lines, it too would catch SIGPIPE.

Grading

12 points total.

Part i: 1 point for b. 0.5 for e.
Part ii: 1 point for a. 0.5 for b or e.
Part iii: 1 point for a. 0.5 for b or e.
Part iv: 1 point for c.
Part v: 1 point for e. 0.5 for b or a.
Part vi: 1 point for a. 0.5 for b or e.
Part vii: 1 point for f or h.
Part viii: 1 point for a or h. 0.5 for b or e.
Part ix: 1 point for a or h. 0.5 for b or e.
Part x: 1 point for b. 0.5 for e.
Part xi: 1 point for c. 0.5 for a.
Part xii: 1 point for g.