Question: please answer the following hw question The following program is executed and the parent and child processes are given the parent PID of 2500 and
please answer the following hw question
The following program is executed and the parent and child processes are given the parent PID of 2500 and child PID of 2603. What are the values of the variable pid1 and pid2 at the lines labeled A, B, C, and D in the comments in the code.
#include
#include
#include
int main() {
pid_t pid1, pid2;
pid1 = fork(); //*A*
if (pid1 < 0) {
printf("Error!")
}
else if (pid1 == 0) {
pid2 = getpid(); //*B*
printf("c: pid1 = %d ", pid1);
printf("c: pid2 = %d ", pid2);
}
else {
pid2 = getpid(); //*C*
printf("p: pid1 = %d ", pid1);
printf("p: pid2 = %d ", pid2);
}
return 0; //*D*
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
