Question: 2 . Using the following program, explain what the output will be at LINE A , B , C , D and E . Explain

2. Using the following program, explain what the output will be at LINE A, B, C, D and E. Explain why you have 3 different pids and why these process ids are different for each run. Note that getpid() returns the process ID and getppid() returns the parent process ID. Use ps command to find the bash PID and compare it with the one you find. To get full mark show the print screen. Dont explain the code but explain what you understand from the screen. #include #include #include int main(){ pid_t pid, pid1; 2 pid1= getpid(); printf("Creator: pid1=%d
",pid1); /* E *//* fork a child process */ pid = fork(); if (pid <0){/* error occurred */ fprintf(stderr, "Fork Failed"); return 1; } else if (pid ==0){/* child process */ pid1= getpid(); printf("Child Process: Process ID (pid) : %d
",pid); /* A */ printf("Child Process: Process ID (pid) using getpid(): %d
",pid1); /* B */ printf("Child Process: Process ID (pid) using getppid(): %d
",getppid()); /* C *} else {/* parent process */ pid1= getpid(); printf("Parent Process: Process ID (pid) : %d
",pid); /* D */ printf("Parent Process: Process ID (pid) using getpid() : %d
",pid1); /* E */ printf("Parent Process: Process ID (pid) using getppid(): %d
",getppid()); /* F */ wait(NULL); } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!