Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS3733: Homework/Practice 05 Suppose we would like to write a program called monitor which allows two other programs to communicate with each other through the

image text in transcribed

CS3733: Homework/Practice 05 Suppose we would like to write a program called monitor which allows two other programs to communicate with each other through the monitor while inspecting the send messages. It can be executed as follows: > monitor progl prog2 To simplify the implementation, we assume that prog1 (e.g., 1s) will be printing some messages on the standard output while the prog2 (e.g, sort) reads from standard input and writes something into standard output. Our monitor can run these two programs as children and let the first one send messages to the second one through our monitor. So our monitor can inspect the incoming messages. After inspection, it sends the message to the next program as is. Again to simplify the implementation, we assume that our monitor simply looks for digits. When it detects a digit in the message, our monitor simply prints it on the stderr (this monitoring task can be complicated for other purposes) Logically these programs will have the following relationship prog1(child11Pie>[0Monitor (Paren)[1>Pipe2->[0Kprog2 (child2) You are asked to create the necessary pipes, child processes 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 descriptors and check what read-write return > monitor /bin/ls /usr/bin/sort #include #include #include #include int main (int argc, char argv int Pipel [2]; int Pipe2 [2] int chlpid, ch2pid, numread, numwrite; char buf if (chlpid.. 0){ /* child 1 7/ execl (argv[1], "progl", NULL) if (ch2pid0)/child 1 / execi (argv[2],"prog2", NULL) CS3733: Homework/Practice 05 Suppose we would like to write a program called monitor which allows two other programs to communicate with each other through the monitor while inspecting the send messages. It can be executed as follows: > monitor progl prog2 To simplify the implementation, we assume that prog1 (e.g., 1s) will be printing some messages on the standard output while the prog2 (e.g, sort) reads from standard input and writes something into standard output. Our monitor can run these two programs as children and let the first one send messages to the second one through our monitor. So our monitor can inspect the incoming messages. After inspection, it sends the message to the next program as is. Again to simplify the implementation, we assume that our monitor simply looks for digits. When it detects a digit in the message, our monitor simply prints it on the stderr (this monitoring task can be complicated for other purposes) Logically these programs will have the following relationship prog1(child11Pie>[0Monitor (Paren)[1>Pipe2->[0Kprog2 (child2) You are asked to create the necessary pipes, child processes 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 descriptors and check what read-write return > monitor /bin/ls /usr/bin/sort #include #include #include #include int main (int argc, char argv int Pipel [2]; int Pipe2 [2] int chlpid, ch2pid, numread, numwrite; char buf if (chlpid.. 0){ /* child 1 7/ execl (argv[1], "progl", NULL) if (ch2pid0)/child 1 / execi (argv[2],"prog2", NULL)

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_2

Step: 3

blur-text-image_3

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

1. Television more Over watching faceing of many problems ?

Answered: 1 week ago

Question

Is there a link between chronic stress and memory function?

Answered: 1 week ago

Question

=+ d. a professor deciding how much to prepare for class

Answered: 1 week ago