Question: Forking Source: not require for this question (15 pts.) For the pseudo-C code program that follows, the instruction path can follow one of three scenarios:
Forking
Source: not require for this question (15 pts.) For the pseudo-C code program that follows, the instruction path can follow one of three scenarios:
P Parent process, fork() successful
C - Child process, fork() successful
E Parent process, fork() fails i.e. ERROR
- Assume the shell process has a PID of 500. - Assume parent process instance was run from that shell, the parent process is assigned the PID of 700 by the OS. - Assume any child process created have PIDs assigned sequentially by the OS i.e. 701,
[Optional Hint: I have provided a CSCACAD compiling source code copy of the C program below is in ~/jgarv2/ csc389/final/q5p3/finalq5p3.c If you use it, you must still use the PIDs above (500, 700, 701, ) in your answer (not those you see on CSCACAD)]
For each //statement #: ___, using a combination of the letters (PCE, PC, PE, CE, P, C, E) to indicate if the statement is executed in a scenarios path. Some statements are used in more than one scenarios path.
Clarification: Conditional clauses statements (if, else if) are considered executed by a path if tested, regardless of T/F outcome
int main() {
int wstat, num1, num2, num3, num4, num5; num1=num2=num3=num4=num5=0;
num1 = fork();
if ( num1 == -1 ) { // statement 1: ___
num2 = 11; // statement 2: ___
}
else if ( num1 > 0 ) { // statement 3: ___
num2 = 22; // statement 4: ___
}
else { // statement 5: ___
num2 = 33; // statement 6: ___
}
num3 = getpid(); // statement 7: ___
num4 = getppid();
if ( num1 > 0 ) { // statement 8: ___
num5 = wait(&wstat); // statement 9: ___
}
printf(%d %d %d %d %d , num1, num2, num3, num4, num5);
exit(0); // statement 10: ___
}
What numbers are printed by each scenario?
Remember; use the PID numbers in the assumptions (500, 700, 701, ).
P: ___ ___ ___ ___ ___
C: ___ ___ ___ ___ ___
E: ___ ___ ___ ___ ___
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
