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

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 progl(child 1)[1]- Pip 1 -plom nitor (Paren)[1] > | Pip 2 [OK rog2(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/1s /usr/bin/sort #include #include #include #include int main (int argc, char arg [ int Pipel [21; int Pipe2 121 int chlpid, ch2pid, numread, numwrite; char buf: if (ch1pid == 0){ /* child 1 */ execl (argv1], "progl", NULL) if(ch2pid == 0){ /* child 1 */ execl (argvI21,"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

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

Demonstrate three aspects of assessing group performance?

Answered: 1 week ago