Question: fork int x; int main ( int argc, char * argv [ ] ) { pid _ t pid 1 , pid 2 ; int

fork
int x; int main(int argc, char *argv[]){
pid_t pid1, pid2;
int y;
x = atoi(argv[1]);
y = atoi(argv[2]);
pid1= fork();
if (pid1<0)
{ fprintf(stderr, "Fork Failed");
return 1;
} else if (pid1==0){
x *=2;
y *=2;
pid2= getpid();
printf("%d
", pid1); // A: 0
printf("%d
", pid2); // B
printf("%d %d
", x, y); // C
} else {
x /=2;
y /=2;
pid2= getpid();
wait(NULL);
printf("%d
", pid1); // D
printf("%d
", pid2); // E
printf("%d %d
", x, y); // F
}
return 0;
}
We consider the above program for the question at the right side: The above program takes two input arguments and assigns them to x and y, respectively. We consider one instance: x is initialized as 110 and y is initialized as 220. We also assume that the actual pids of the parent and child are 5671 and 5672, respectively. Identify the values at Lines B, C, D, E, and F by running the program:
B: pid2=
C: x =
y =
D: pid1=
E: pid2=
F: x =
y =

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!