Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started