subject

You are given the following C code, running under Unix operating system, assuming the following:
(1) system calls never fail; (2) the function Fn() never returns; (3) the function Fn() does not contain any system calls; (4) whenever a process is created, it inherits exactly the same signal handlers as its parent; and (5) system calls cannot be interrupted. Since Fn() never returns, all processes that are created with the following code reach a steady state. This means that the process tree stays the same forever and each process executes a specific function or system call.

void handler (int signum)
{
Fn(0, -1);
}
int main(void)
{
int i, p[2], writefd [4];
pid_t pid [4];
signal (SIGUSR1, handler);
for (i = 0; i < 4; i++) {
pipe (p);
pid[i] = fork();
if (pid[i] == 0) {
close (p [1]);
read (p [0], &pid[i], sizeof(pid_t));
if (pid[i] > 0) kill (pid[i], SIGUSR1);
Fn(i, pid[i]);
}
close (p [0]);
writefd[i] = p [1];
}
write (writefd [1], &pid [0], sizeof(pid_t));
close (writeid [3]);
wait (NULL);
write (writefd [2], &pid [1], sizeof (pid_t));
Fn(-1, -2);
return 0;
}

1. Answer the following questions:
(a) Describe the functionality of the pipe() system call in Unix. How many and what type of values does it return to the program that uses it?
(b) When does a process turn into a zombie process and how does this process eventually leave the system?
(c) What happens when a process calls read() in an empty pipe while the write edge is open?
(d) What happens when a process calls read() in an empty pipe while the write edge is closed?
(e) What do the system calls getpid() and getppid() do in Unix? Can the return values of each of these system calls change throughout the execution of the same process?
2. Regarding the steady-state of the created processes, draw a process tree that shows how processes are connected. Briefly describe it.
3. For each node (process) of that tree, mention:
(a) the system call or the function that this node (process) executes, and
(b) the arguments with which that system call or function was called. Regarding the arguments you can make assumptions for the values you do not know (e. g., PIDs assigned to new processes).

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 10:30, ilovepickles930
What can tanya do now to start preparing for the college and scholarship application process? think about her grades, activities in which she can get involved, possible part-time jobs at which she can work, and standardized tests she can take. (10 points) apex
Answers: 2
image
Computers and Technology, 22.06.2019 20:00, random286
How is the number 372 written when expanded out to place values in the base 8 (octal) number system? a. 2 x 4 + 3 x 2 + 4 x 1 b. 3 x 64 + 7 x 8 + 2 x 1 c. 3 x 8 + 7 x 7 + 2 x 6 d. 3 x 100 + 7 x 10 + 2 x 1
Answers: 1
image
Computers and Technology, 24.06.2019 10:30, johngayden46
This device directs network traffic. bridge hub nic repeater router switch
Answers: 3
image
Computers and Technology, 24.06.2019 11:00, dirttrackr75
Which of the statements below describe the guidelines for the use of text in presentation programs? a. do not use numbered lists. b. fonts should be appropriate for your audience. c. limit the number of fonts you use to three or four. d. only use bulleted lists for sales promotions. e. select font sizes that are appropriate for your delivery method. f. use font colors that work well with your background. select all that apply
Answers: 1
You know the right answer?
You are given the following C code, running under Unix operating system, assuming the following:

Questions in other subjects:

Konu
Mathematics, 13.11.2019 08:31