University of Pennsylvania / CIS Department
Spring 2007
CSE-380 (Operating Systems)
Matt Blaze (blaze at-sign cis.upenn.edu)
Extra Credit -- Due: Monday, October 22, 2007 (1800 EST)
No late work accepted!

Important Note

This is extra credit. Don't do it in place of your normal work; it's not a good use of time. This is only a small amount of extra credit.

To submit your work, send it in EMAIL to cse380 at-sign seas.upenn.edu. Do not use the submission system. Send ASCII text only. No attachments. Anything with an attachment or a proprietary document format (e.g., MS Word) will not be graded.

Extra Credit

Recall the following code snippet from the midterm:

#include <stdio.h>
main()
{
        int i, j=0;

        for (i=0; i<3; i++) {       /* loop three times */
                if (fork() == 0) {  /* if we're in child */
                        j = j + 1;  /* increment j when we print */
                        printf("Feckless forks in parallel!\n");
                }
        }
        if (j > 3)  /* check to make sure only three messages printed */
                printf("Something is wrong here...\n");
}

Suppose you compile this into something called praise. How many lines does it print when you invoke it by itself? What about when you invoke it as praise | cat ?

Notice that piping the output into cat gives you a result very different from what you get when you run it by itself. How could that be? What if you change the printf() to a write()?

Write a brief essay explaining exactly why this confusing behavior happens. Be precise. Investigate sufficently well that you don't have to submit a wild guess. If you just guess or submit only a vague, incomplete, or inarticulate response, you won't get any extra credit, so submit only if you're confident that you understand what's going on.



Course home page: http://www.crypto.com/courses/fall07/cse380/