Answers to Question 2 (11 points, 20 minutes)

Part 1 (8 points)

If you understood setjmp()/longjmp(), then this part should have been a straightforward trace through the program. Thus, the program's output looks like:
i = 0.  j = 0
Calling fork()
i = 0.  j = 1
i = 1.  j = 1
Calling fork()
i = 1.  j = 2
i = 2.  j = 2
Calling fork()
i = 2.  j = 3
2 3 Exiting
2 2 Exiting
1 1 Exiting
0 0 Exiting

Grading

It's hard to quantify how to grade this question. Basically, there were two kinds of answers -- those that were close to right, and those that were nowhere close to right. When grading questions that were close to right, I started with 8 points and deducted for things that were wrong. When grading questions that were nowhere close to right, I started with 0 points and added for things that looked good.

Part 2 (3 points)

Yes, the output would be different. This is because the buffers for standard output are not flushed at the end of a line. Thus, each process would have all the output from its ancestor processes to that point in its buffer. I.e.: This gives the following output:
i = 0.  j = 0
Calling fork()
i = 0.  j = 1
i = 1.  j = 1
Calling fork()
i = 1.  j = 2
i = 2.  j = 2
Calling fork()
i = 2.  j = 3
2 3 Exiting
i = 0.  j = 0
Calling fork()
i = 0.  j = 1
i = 1.  j = 1
Calling fork()
i = 1.  j = 2
i = 2.  j = 2
Calling fork()
2 2 Exiting
i = 0.  j = 0
Calling fork()
i = 0.  j = 1
i = 1.  j = 1
Calling fork()
1 1 Exiting
i = 0.  j = 0
Calling fork()
0 0 Exiting

Grading

To get full credit, you had to say something equivalent to the first three sentences of this answer. You did not have to give any output.