Question: 5. [20 points] IPC and pipes -fifo Write a program (say prog.c) that forks and runs a sub-shell as a child process, and simply counts

 5. [20 points] IPC and pipes -fifo Write a program (sayprog.c) that forks and runs a sub-shell as a child process, and

5. [20 points] IPC and pipes -fifo Write a program (say prog.c) that forks and runs a sub-shell as a child process, and simply counts the number of output characters that the shell printed on the standard output. When the sub-shell terminates, the parent simply reports the number of output characters produced by the sub-shell. For parent to do its job, it needs to get everything the child shell prints on the standard output. Hope you see how a pipe will be useful here child [1:STDOUT_FILENO] -> pipe[0: STDIN FILENO] parent. Since now the parent can get everything the child writes on the standard output, the parent can count the number of characters and write them into its own standard output. You are asked to complete the following program so you can create the necessary pipe, child process and connect them as explained in the above scenario. You can ignore most of the error checking to make your solution clear, but you need to close all unnecessary file or pipe descriptors and check what read-write etc return. Also read/write one char at a time to make counting job easy! /*your simple implementation of prog.c * #include #include #include #include int main (int argc, char *argv[]) int mypipe [2]; int childpid, numread, numwrite, count 0; char buf; /4pt - create pipe and child process if (chi ldpid = 0){ /* child */ 4pt - child sets up the pipe execl("/bin/bash", "shell", NULL) perror ("cannot start shell"); return 1; /*continue in the next page*/

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!