Question: Processes Answer the following questions, considering the following C code and a program pin obtained by compiling it with gcc: int main ( int argc,char

Processes
Answer the following questions, considering the following C code and a program pin obtained by compiling it with gcc:
int main(int argc,char* argv[])
{
int n = atoi(argv[1]);
printf("PIN NUMBER for %d:
",n);
int pid = fork();
if (pid %2){
n +=1;
int pid2= fork();
if (!pid2){
n +=2;
}
else {
n -=1;
}
}
else {
n+=1;
if (!fork()){
n-=1;
}
}
n+=1;
printf("%d",n);
return 0;
}
(a) How many input takes the program pin?
(b) What are the values of variable pid and pid2?
(c) Briey explain what does the function fork() do:
(d) How many times the printf function is called:
(e) Draw clearly the process graph, marking the modifications happening to the number n:
(f) Suppose that the number n is initially 1, provide a feasible ouput for the program:
Processes Answer the following questions,

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