strcpybuf cmdline bufstrlenbuf 1 replace

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ting the Ø lexical instance of the fork function in the source code. For example, how many lines of output would the program in Figure 8.14(a) generate? Figure 8.14(b) shows the corresponding process hierarchy. The parent creates the child when it executes the first (and only) fork in the program. Both and call printf once, so the program prints two output lines. Now what if we were to call fork twice, as shown in Figure 8.14(c)? As we see from the process hierarchy in Figure 8.14(d), the parent creates child when it calls the first fork function. Then both and execute the second fork function, which results in the creations of and , for a total of four processes. Each process calls printf, so the program generates four output lines. Continuing this line of thought, what would happen if we were to call fork three times, as in Figure 8.14(e)? As we see from the process hierarchy in Figure 8.14(f), the first fork creates one process, the second fork 8.4. PROCESS CONTROL 407 1 2 3 4 5 6 7 8 #include "csapp.h" int main() { Fork(); printf("hello!\n"); exit(0); } a 1 b (a) Calls fork once. (b) Prints two output lines. 1 2 3 4 5 6 7 8 9 #include "csapp.h" int main() { Fork(); Fork(); printf("hello!\n"); exit(0); } a 1 b 2 2 c d (c) Calls fork twice. (d) Prints four output lines. 1 2 3 4 5 6 7 8 9 10 #include "csapp.h" int main() { Fork(); Fork(); Fork(); printf("hello!\n"); exit(0); } 3 e f g h a 1 b 2 2 c d 3 3 3 (e...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online