Question
Assume that the PID of the main process is 42. Each call to fork() in the code is commented to show the PID of the
Assume that the PID of the main process is 42. Each call to fork() in the code is commented to show the PID of the newly created process (The PIDS are thus 42, 11, 25, 89, and 123).
In this exercise, we assume that all operations take zero time but for sleep() (which sleeps a prescribed number of seconds) and waitpid(), which obviously might block for a while. We also assume that the execution starts at time zero. Therefore, in all the questions below, whenever the time is mentioned/needed, its always a perfect multiple of 10 (since all calls to sleep in the above program are for numbers of seconds that are multiples of 10).
**Assume that necessary header files are included and that there are no compilation or execution errors**
int main(int argc, char **argv) { // Main process's PID=42 pid_t pid = fork(); // creates process with PID=11 if (pid > 0) { pid_t pid2 = fork(); // creates process with PID=25 if (pid2 > 0) { sleep(20); // sleep for 20 seconds exit(0); } exit(0); } else { pid_t pid3 = fork(); // creates process with PID=89 if (pid3 == 0) { sleep(40); // sleep for 40 seconds printf("** ONE ** "); exit(0); } pid_t pid4 = fork(); // creates process with PID=123 if (pid4 == 0) { sleep(30); // sleep for 30 seconds exit(0); } waitpid(pid4, NULL, 0); } sleep(20); // sleep for 20 seconds printf("** TWO ** "); exit(0); }
Answer the following questions:
1. What time is ** ONE ** printed to the terminal?
2. What time is ** TWO ** printed to the terminal?
3. What is the PID of the process that prints ** TWO **?
4. What is the PPID of the process with PID 89?
5. What time does the process with PID 123 terminate?
6. What time would ** TWO** be printed if line 25 were removed?
7. Give the PID of a process that is a zombie at the time when ** TWO ** is being printed
8. Give the PID of a non-zombie process that at some point in the execution becomes an orphan
9. Which processes are alive (i.e., not terminated nor zombies) right before process with PID 123 terminates (PID 123 is thus one of these)?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started