Question: Draw the corresponding process tree for the code below. Use circles to model processes. Also picture pipes ( using a cylinder ) and show fork,

Draw the corresponding process tree for the code below. Use circles to model processes. Also
picture pipes (using a cylinder) and show fork, exec, wait, and pipe function calls. (Use the next
page for this).
What is the written on STDOUT and STDERR? Assume the starting process id is 100.
const int NUM_KIDS =3;
const int MSG_SIZE =16;
int main ()(
int fd[NUM KIDS][2];
pid_t pid[MM_KIDS];
cerr "Start pid: " getpid() endl;
for (int i=0;i NUM KIDS; i++)(
pipe (fd[i]);
pid[i]= fork(); // Assume no error
if (pid[i]==0){
cerr "i =" i ", pid: " getpid() endl;
close (fd[i][0]);
dup2(fd[i][1],1);
cout getpid()"-" i endl;
exit (0);
}) else {
close (fd[i][1]);
}
}
for (int i=0; i NUM_KIDS; i++){
char msg[MSG_SIZE];
read(fd[i][0], msg, MSG_SIZE);
cout "msg: " msg endl;
waitpid(pid[i], NULL, 0); // Block and wait
close (fd[i][0]);
}
}
 Draw the corresponding process tree for the code below. Use circles

Step by Step Solution

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 Databases Questions!