+1(805) 568 7317

please help write a c program that creates 2 child processes 1 and2 and 2 pipes and 5196178

Please Help:

Write a C program that creates 2 child processes(1 and2) and 2 pipes and support sending an unlimited number of messages between the parent

and either of the 2 child processes.The parent process reads the ID of the destination process as well as the message itself from the user and sends the message through the correct pipe to its intended destination. The sender process ignores any messages that are destined to neither of the children. As soon as a child process receives a message it prints it to the screen as shown in the sample run below.The parent process will keep on reading messagesfrom the user and sending them to the destination processes until the user types -1 for the ID of the destination.It then closes all open pipes and terminates.Please test for the success of the different system calls you use in your code, and make sure that the parent processwaits for its children before it terminates.

Your program should behave as follows:

After opening the pipes and creating the children, the parent process should prompt the user for the messages in the form: ” “:

1)You may assume that messages are only one word in length (you do not need to handle spaces in messages).

2)The parent will then use pipes P1 and P2 to send all the messages to the appropriate children.

3)Each process should ensure that its pipes are unidirectional.

4)Once received, a message is printed out in the form:

—> Child 1 received: msg_1_to_child_1

A sample run is shown is below:

1.)3 messages are sent to child process 1. These messages are received and printed by process 1.

2.)2 messages were sent to child process 2. The messages were received and printed by process 2.

3.)A message was sent to process 7. It was ignored and an error message was printed by the parent process.

4.)The process terminates as soon as the user types -1 and hits enter.



To avoid blocking reads in the children, you should consider what happens when processes close one end of a pipe.

To guarantee the order of printing to the screen make sure that the parent process sleeps for a fraction of second. Investigate using the function usleep().

Assume a maximum message size of 64 bytes.

int fd[2];

int pipe(int filedes[2]);

int open(const char *path, int oflags);

int open(const char *path, int oflags, mode_t mode);

ssize_t read(int fd, void *buf, size_t count); ssize_t write(int fd, const void *buf, size_t count);

int usleep(useconds_t usec);

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon

Order Now