Take a look at the C code (fa-pipe.c) shown below. Assume that all system and library...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 <sys/types.h> #include <sys/wait.h> #include <stdlib.h> #include <unistd.h> 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? 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 <sys/types.h> #include <sys/wait.h> #include <stdlib.h> #include <unistd.h> 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?
Expert Answer:
Answer rating: 100% (QA)
a The program creates a pipe using the pipe system call It then forks twice to create two child proc... View the full answer
Related Book For
Accounting Information Systems
ISBN: 9780132871938
11th Edition
Authors: George H. Bodnar, William S. Hopwood
Posted Date:
Students also viewed these programming questions
-
Predictive text entry systems are familiar on touch screens and mobile phones. This question asks you to consider how the same principles might be used in a programming editor for creating Java code....
-
This question concerns lexical grammars. (a) Tree Adjoining Grammars contain two types of elementary tree. (i) What are these trees called? [1 mark] (ii) If one were building a grammar for English...
-
A reducing elbow in a horizontal pipe is used to deflect water flow by an angle u = 45? from the flow direction while accelerating it. The elbow discharges water into the atmosphere. The cross-...
-
On June 5, 2014, Dan purchased and placed in service a 7-year class asset costing $550,000. Determine the maximum deductions that Dan can claim with respect to this asset in 2014 and 2015.
-
mass of water = 26.11g Volume of head block is = 1.17 of a Hond 4 STROKE engine , Calculate the compression ratio of this engine, using the measurements
-
A horizontal, 25-mm-diameter cylinder is maintained at a uniform surface temperature of \(35^{\circ} \mathrm{C}\). Air at atmospheric pressure with a velocity of \(0.10 \mathrm{~m} / \mathrm{s}\) and...
-
Papas Restaurant Corporation wholesales ovens and ranges to restaurants throughout the Northeast. Papas Restaurant Corporation, which had 18,000 shares of common stock outstanding, declared a 4-for-1...
-
25 28 30 30 Sheridan Manufacturing Company uses a job order cost system and keeps perpetual inventory records. June 1 Purchased raw materials for $22,800 on account. 8 Raw materials requisitioned by...
-
Salmon Limited reported profit of $465,325 for its November 30, 2021, year end. Cash dividends of $90,000 on the common shares and $65,000 on the noncumulative preferred shares were declared and paid...
-
Which of the following regular expressions represent this finite state automata? 90 O 1. null+bb(b+abb)*aa O2. b(bab)*a + NULL q1 93 b 92
-
While performing a routine audit, an organization discovers it has been overpaid for a claim. What is the next step?
-
what is some steps by resetting the root password in Microsoft Windows?
-
A certain type of thread is manufactured with a mean tensile strength of 78.3kg and standard deviation of 5.6kg. Assuming that the strength of this type of thread is distributed approximately normal,...
-
ADVANTAGES AND DISADVANTAGES OF MAC OS , LINUX AND MICROSOFT WINDOWS ?
-
If Canada did not buy and sell goods internationally, how would your community be affected?
-
Choose and create a post from one content area across from the readings, handouts, or narrated lectures from module 5. Post your initial response by Thursday, 11:59 pm. Topics should come from module...
-
The following items were displayed in the statement of affairs for Lubbock Company: Fully secured liabilities ......... $90,000 Partially secured liabilities ....... 12,000 Unsecured liabilities...
-
How might an investigator obtain the physical location associated with a computer device that is used to communicate over the Internet?
-
Define each of the following terms. a. PERT chart b. Gantt chart c. Critical path d. Parallel operation e. Modular conversion f. Test data
-
You are in the process of designing an accounts receivable system for your company. A local computer retailer hears that you are designing a system and calls on you. He tells you that he can sell you...
-
What would be the most effective option to increase employee motivation to stay and reduce the driver turnover rate? Why do you believe this option will be effective?
-
How else might the manager have handled the situation to prevent potential issues, including a negative impact on the teams performance?
-
In what ways do you believe providing special work arrangements or accommodations for employees impacts employee motivation? How does it help? How does it hurt?
Study smarter with the SolutionInn App