Question: The program shows basic pipe usage in UNIX. In the program, parent process writes a message to pipe and child process reads the message

The program shows basic pipe usage in UNIX. In the program, parent

 process writes a message to pipe and child process reads the message

The program shows basic pipe usage in UNIX. In the program, parent process writes a message to pipe and child process reads the message from pipe and prints it to screen. Let's assume that a process forks two child processes (C1, C2). Then, three processes communicate with each other in a circular fashion as shown in the right figure. The parent process (P) sends data to the first child process (C1), this one sends the same data to the second child process (C2), and eventually, the second one sends the same data back to the parent process (P). a) How many pipes do you define? Explain your reasoning. b) Write the code to implement this inter-process communication case. O C1 #define MSGSIZE 5 int main() { char inbuf [MSGSIZE]; int p[2], pid, nbytes; if (pipe (p) < 0) exit (1); if ((pid = fork ()) > 0) { write (p[1], "Hello", MSGSIZE); wait (NULL); } else { read (p[0], inbuf, MSGSIZE); printf("%s ", inbuf); } return 0;

Step by Step Solution

3.54 Rating (147 Votes )

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 General Management Questions!