Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions