Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

Write a letter asking them to refund your $1,500 down payment.

Answered: 1 week ago