operating system
Question Description
Explain in detail for all
processes (parent and any children) what happens when each statement in the
code below is executed and by which process, and what is printed by each
process.
- Assume the shell process has a PID of 100.
- Assume parent process program instance, run from that shell, is assigned the
process PID of 300 by the OS.
- Assume any additional process created have PIDs assigned sequentially by the
OS i.e. 301, …
int main() {
int wstat, num1, num2, num3, num4, num5;
num1 = 33;
num2 = fork();
if ( num2 == -1 ) {
exit(1);
}
else if ( num2 > 0 ) {
num1 = 66;
}
else {
num1 = 99;
}
num3 = getpid();
num4 = getppid();
printf(“num1 = %d\n”, num1);
printf(“num2 = %d\n”, num2);
printf(“num3 = %d\n”, num3);
printf(“num4 = %d\n”, num4);
if ( num2 > 0 ) {
num5 = wait(&wstat);
printf(“num5 = %d\n”, num5);
}
exit(0);
}
This question has not been answered.
Create a free account to get help with this and any other question!
Brown University
1271 Tutors
California Institute of Technology
2131 Tutors
Carnegie Mellon University
982 Tutors
Columbia University
1256 Tutors
Dartmouth University
2113 Tutors
Emory University
2279 Tutors
Harvard University
599 Tutors
Massachusetts Institute of Technology
2319 Tutors
New York University
1645 Tutors
Notre Dam University
1911 Tutors
Oklahoma University
2122 Tutors
Pennsylvania State University
932 Tutors
Princeton University
1211 Tutors
Stanford University
983 Tutors
University of California
1282 Tutors
Oxford University
123 Tutors
Yale University
2325 Tutors