Question: Write a program which implements the eect of a three-command pipeline, cmd-1 | cmd-2 | cmd-3, where cmd-i is the i-th line in the le
Write a program which implements the eect of a three-command pipeline, cmd-1 | cmd-2 | cmd-3, where cmd-i is the i-th line in the le cmds. The current content in le cmds is: cat Makefile head -4 wc -l Therefore, running your program would give us the same result as running cat Makefile | head -4 | wc -l. Your program should also prints when each child process executes its command and when the parent process reaps each of the child processes. The output of your program with the current cmds le content should look like:
In the above output, 4 is the result of the command pipeline. Please also note that: You can assume each line in the cmds le contains at most 63 characters, and has at most 8 tokens. Only spaces are use to separate tokens in the cmds le. One of the exec functions (e.g., execl, execlp, execle, execv, execvp, execvpe) should be used to execute commands in the child processes. Learning how to use these functions and choosing a proper one according to your program design is part of this tasks goal. You will need to properly redirect standard input/output of each child process to the read/write end of each pipe. The dup() or the dup2() functions can help you achieve the goal.
-E |@) cs550-19s-proj1.pdf >+v O file:///C/Users/aravi/Downloads/my%20folder%20-aravind/cs550-19s-proj1.pdf file content should look like: In CHILD-1 (PID-15688): executing command cat .. . In CHILD-2 (PID-15689): executing command head In CHILD-3 (PID-15690): executing command wc .. . In PARENT (PID-15687) successfully reaped child (PID 15688) 4 In PARENT (PID-15687) successfully reaped child (PID-15689) In PARENT (PID-15687): successfully reaped child (PID-15690) above output, "4" is the result of the command pipeline. Please also note that: ou can assume each line in the "cmds" file contains at most 63 characters, and has at mo tokens. O Type here to search t 10:39 AM 2/28/2019 -E |@) cs550-19s-proj1.pdf >+v O file:///C/Users/aravi/Downloads/my%20folder%20-aravind/cs550-19s-proj1.pdf file content should look like: In CHILD-1 (PID-15688): executing command cat .. . In CHILD-2 (PID-15689): executing command head In CHILD-3 (PID-15690): executing command wc .. . In PARENT (PID-15687) successfully reaped child (PID 15688) 4 In PARENT (PID-15687) successfully reaped child (PID-15689) In PARENT (PID-15687): successfully reaped child (PID-15690) above output, "4" is the result of the command pipeline. Please also note that: ou can assume each line in the "cmds" file contains at most 63 characters, and has at mo tokens. O Type here to search t 10:39 AM 2/28/2019
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
