Question: Part 1 & 2 Consider that the system calls do not fail, function f ( ) never returns or exits, f ( ) does not

Part 1 & 2 Consider that the system calls do not fail, function f () never returns or exits, f () does not execute system calls, each new process inherits exactly the way signals are handled by the parent process. Assume that process 400 executes this program, and thereon every new process forked has its pid incremented by 1.
Part 1(4 pts): Explain how the program works.
Part 2(3 pts): Draw the process tree in its final form, i.e., when all processes have reached a steady state. Solve potential race condition, assuming that at least three processes arrive at the point marked /* A */, passing the read () in the order of their birth. At each node of the tree process please highlight:
(i) the system call or a function where the Program Counter of the corresponding process is found, (ii) the arguments with which the function f has been called,
(iii) the program line from which the call took place.
(iv) Complete the process tree to show the inter-process communication using arrows and type above the arrow the value that is transferred each time.
1 int fd[2];
2
3 void handler(int signum)
4{ exit(14); f(14,-14); }
5
6 int main(void)
7{
8 int i, j, n;
9 char c[10];
10 pid_t pid[4];
11
12 signal(SIGUSR1, handler);
13
14 pipe(fd);
15 for (i =0; i 4; i++){
16 pid[i]= fork();
17 if (pid[i]==0){
18 n = read(fd[0], c, i +2);
19/* A */
20 for (j =0; j n; j++){
21 pid[i]= fork();
22 if (pid[i]==0)
23 f(getpid(), j);
24}
25 for (j =0; j i; j++)
26 wait(NULL);
27 f(i,10);
28 exit(2);
29}
30}
31
32 kill(pid[i -2], SIGUSR1);
33 for (i =0; i 4; i++){
34 wait(&n);
35 write(fd[1], c, WEXITSTATUS(n));
36}
37 f(i,-6);
38 return 0;
39}
 Part 1 & 2 Consider that the system calls do not

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!