Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assume pr1 always executes first and is invoked as follows: ./pr1 How many unique processes do the programs pr1 and pr2 create when executed, including
Assume pr1 always executes first and is invoked as follows: ./pr1
- How many unique processes do the programs pr1 and pr2 create when executed, including the initial process? Provide a brief explanation.
- What will these programs print? (Choose one valid sequence and display it.)
prl: int main(int argc, char **argv) { pid_t pidi, pid2; pr2: int main(int arge, char **argv) { pid_t pid; pidl = fork(); if (pidl == 0) { printf ("P1 child "); execlp ("./pr2", "pr2", "fork 1", NULL); } else { printf ("P1 original "); wait (NULL); printf ("P2 %s ", argv[1]); pid = fork(); if (pid > 0) { wait (NULL); printf ("P2 parent ts ", argv[1]); } else if (pid == 0) printf ("P2 child ts ", argv[1]); return 0; pid2 = fork(); } if (pid2 == 0) { printf ("Child of P1 "); execlp("./pr2", "pr2", "fork 2", NULL); } else { printf ("Still P1 original "); wait (NULL); } } return 0; }
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