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-...
-
Jabari Johnson is considering acquiring an automobile at the beginning of 2015 that he will use 100% of the time as a taxi. The purchase price of the automobile is $35,000. Johnson has heard of cost...
-
The data in the accompanying table represent the concentration of glucose in the blood serum of an adult patient. On four consecutive days, a blood sample was drawn from the patient and analyzed in...
-
The company is committed to ethical conduct and has no tolerance for fraud and unethical behavior. There are some concerns about abuses in your department. Do you know anything about the concerns I...
-
Beagle Clothiers uses a weighted score for the evaluation and selection of its suppliers of trendy fashion garments. Each supplier is rated on a 10-point scale (10 = highest) for four different...
-
Direct Materials Conversion Percent Percent Units Complete Beginning work in process inventory 2,800 100% Complete 25% Units started this period 6,800 Completed and transferred out 7,800 Ending work...
-
Use the cutting plane method to find the solution of the following IP model. max z=X+3X2 s.t. 5X1+2X2 13 X + X2 30 X 1 X1, X2 0 and X2: integer
-
What is the annual report, and what two types of information does it provide?
-
Common uses of analytical procedures include: a. risk identification during the risk assessment phase. b. estimation of account balances during the risk response phase. c. overall assessment of the...
-
Explain why environmental damage costs are an externality. Use some concrete exam ple(s) to support your answer.
-
"The price of anything is the amount of life you exchange for it." What does this quote from Henry David Thoreau say about valuing nature? Speculate.
-
Discuss at least two differences among the strategic, tactical, and operational decisions in a supply chain. Give two examples of each type of decision.
-
Pittman Company is a small but growing manufacturer of telecommunications equipment. The company has no sales force of its own; rather, it relies completely on independent sales agents to market its...
-
Illini Company, Inc. Balance Sheet as of 12/31/20X0 Assets Current Assets: Cash $1,500,000 Accounts receivable, net 18,000 Inventory 50,000 Total current assets 1,568,000 Equipment 90,000 Goodwill...
-
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...
-
Select the circumstance in which the impact on government bond yields of a new source of revenue (such as a natural resource discovery) would be largest. Explain your choice. a. Before the discovery,...
-
Discuss how yields anticipate future economic activity.
-
Suppose the yields on tax-exempt local government bonds in Problem 9 initially were below the Treasury yields of the same maturity. If the tax-exempt status were then removed from the local...
Study smarter with the SolutionInn App