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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 19:20
Amedian in the road will be marked with a white sign that has a black arrow going to the left of the median. true false
Answers: 1
question
Computers and Technology, 23.06.2019 01:40
Writing a modular program in visual c++. i am new to this and not sure what i am missing. i am getting the following error: baddate.cpp: in function ‘int main()’: baddate.cpp: 50: 3: error: ‘else’ without a previous ‘if’elsehere are the instructions and code: writing a modular program in c++in this lab, you add the input and output statements to a partially completed c++ program. when completed, the user should be able to enter a year, a month, and a day. the program then determines if the date is valid. valid years are those that are greater than 0, valid months include the values 1 through 12, and valid days include the values 1 through 31.notice that variables have been declared for you.write the simulated housekeeping() function that contains the prompts and input statements to retrieve a year, a month, and a day from the user.include the output statements in the simulated endofjob() function. the format of the output is as follows: month/day/year is a valid date.ormonth/day/year is an invalid date.execute the program entering the following date: month = 5, day = 32, year = 2014. record the output of this program.execute the program entering the following date: month = 9, day = 21, year = 2002. record the output of this /* program name: baddate.cppfunction: this program determines if a date entered by the user is valid.input: interactiveoutput: valid date is printed or user is alerted that an invalid date was entered*/#include bool validatedate(int, int, int); using namespace std; int main(){// declare variablesint year; int month; int day; const int min_year = 0, min_month = 1, max_month = 12, min_day = 1, max_day = 31; bool validdate = true; // this is the work of the housekeeping() method// get the year, then the month, then the daycout< < "enter the year"< > year; cout< < "enter the month"< > month; cout< < "enter the day"< > day; // this is the work of the detailloop() method// check to be sure date is validif(year < = min_year) // invalid yearvaliddate = false; else if (month < min_month || month > max_month) // invalid monthvaliddate = false; else if (day < min_day || day > max_day) // invalid dayvaliddate = false; // this is the work of the endofjob() method// test to see if date is valid and output date and whether it is valid or notif(validdate == true); {// output statementcout<
Answers: 1
question
Computers and Technology, 23.06.2019 09:30
After you present a proposal, the committee starts asking you questions, some beyond the strict focus of your proposal. they ask questions about implications in other fields and knowledge about other fields. you are asked to redo your proposal. what is most likely missing? breadth of material depth of material clarity of material details of material
Answers: 1
question
Computers and Technology, 23.06.2019 11:00
This chapter lists many ways in which becoming computer literate is beneficial. think about what your life will be like once you’re started in your career. what areas of computing will be most important for you to understand? how would an understanding of computer hardware and software you in working from home, working with groups in other countries and contributing your talents.
Answers: 1
You know the right answer?
You are given the following C code, running under Unix operating system, assuming the following:
Questions
question
Mathematics, 05.05.2020 18:01
question
Mathematics, 05.05.2020 18:01
question
Mathematics, 05.05.2020 18:01
question
English, 05.05.2020 18:01
Questions on the website: 13722365