Question: C programming problem 1: From the program below, identify the values of the pids at lines A, B, C, and E. (Assume that the pids
C programming problem
1: From the program below, identify the values of the pids at lines A, B, C, and E. (Assume that the pids of the processes are 2600, 2603, and 2675 (in creation order). Also assume that fork will always succeed.)
int main() {
pid_t pid, pid1, pid2;
pid = fork(); pid1 = getpid();
if (pid < 0) {
fprintf(stderr, "Fork Failed");
return 1;
}
else if (pid == 0) {
printf("A: pid = %d", pid);
printf("B: pid1 = %d", pid1);
}
else {
printf("C: pid = %d", pid);
wait(NULL);
pid2 = fork();
if(pid2 == 0) {
printf("D");
}
else {
wait(NULL);
printf("E: pid2 = %d", pid2);
}
}
return 0;
}
2: List all of the possible outputs (just write the A/B/C/D/E indicators for each printf that will run; no need for pids) that could be generated by the previous program. Again assume that fork will always succeed.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
