RobSim
RobSim

Reputation: 41

CSAPP 3e (global): Possible erratum for "Practice Problem 8.3" (p. 781)?

enter image description here

Due to the relative lack of popularity of CSAPP's global edition, I have been unable to figure out whether exercise problem 8.3 (partial screenshots shown above) is entirely correct. I have only found various corrections for the same problem in other editions as well as comments saying that the global version has been essentially overlooked errata-wise. Hence my question. :)

So, on page 781 in "Chapter 8: Exceptional Control Flow" (search for "Practice Problem 8.3" here), the following code snippet is shown, and students are asked to list all possible output sequences:

int main()
{
    if (Fork() == 0) {
        printf("9"); fflush(stdout);
    }
    else {
        printf("0"); fflush(stdout);
        waitpid(-1, NULL, 0);
    }
    printf("3"); fflush(stdout);
    printf("6"); exit(0);
}

The solution then reads as such:

We know that the sequences 936036, 903636, and 093636 are possible because they correspond to topological sorts of the process graph (Figure 8.48). However, sequences such as 036936 and 360369 do not correspond to any topological sort and thus are not feasible.

Does this solution take into account all possible output sequences?

I would have expected to see 930636, but, due to its absence, I am wondering whether I have misunderstood something more fundamental.

Many thanks in advance!

Note 1. Other editions do not seem to have a second printf statement at the end, so I cannot use them to clarify my doubts. I have also typed the code above (as opposed to including it in the photo) since the snippet spans two pages.

Note 2. Regarding the capitalised f in Fork() (see here):

pid_t Fork(void) 
{
    pid_t pid;

    if ((pid = fork()) < 0)
        unix_error("Fork error");
    return pid;
}

Upvotes: 1

Views: 98

Answers (0)

Related Questions