Question: Take a look at the C code (fa-pipe.c) shown below. Assume that all system and library calls succeed at runtime. (All error handling code

Take a look at the C code (fa-pipe.c) shown below. Assume that 

Take a look at the C code (fa-pipe.c) shown below. Assume that all system and library calls succeed at runtime. (All error handling code has been omitted for brevity.) #include #include #include #include int main(int argc, char *argv[]) { pid t pidi, pid2; int fds[2]; char *argv[] { "1s", "-1", "/usr/bin", NULL }; char *argv2]{"more", NULL }; pipe(fds); pidi fork(); if (!pidi) ( } pid2 close (fds[0]); dup2(fds[1], STDOUT_FILENO); close (fds[1]); execvp(argv1 [0], argv1); fork(); if (!pid2) { close (fds[1]); dup2(fds[0], STDIN_FILENO); close (fds[0]); execup(argv2[0], argv2); } close(fds[0]); close (fds[1]); waitpid(pid2, NULL, 0); return EXIT_SUCCESS; a) Describe what the program is doing. b) Show the file descriptor tables of the processes right before the calls to execve() and waitpid (). c) What happens if the programmer mistakenly passes pidi instead of pid2 to the waitpid() call and runs the program from his command shell? d) Assume the first child process experiences a runtime error and it produces an error message. What will happen to the error message? Can the user page back to the error message?

Step by Step Solution

3.47 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a The program creates a pipe using the pipe system call It then forks twice to create two child proc... View full answer

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!