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 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
a The program creates a pipe using the pipe system call It then forks twice to create two child proc... View full answer
Get step-by-step solutions from verified subject matter experts
