Question: ` ` ` 7 . What do you expect when you run the following code assuming that child PID = 7 1 , parent PID

```
7. What do you expect when you run the following code assuming that child PID=71,
parent PID=70?
#include
#include
#include
#include
static int idata =100;
int main(int argc, char *argv[])
{
int istack =200;
pid_t childPid;
switch (childPid = fork())
{
case -1:
printf("error: fork
");
exit(-1);
case 0:
idata++;
istack++;
break;
default:
sleep(2);
idata *=2;
istack *=2;
break;
}
printf("PID =%ld %s idata =%d istack =%d
",(long)getpid(),
(childPid ==0)?"(child)" : "(parent)", idata, istack);
exit(EXIT_SUCCESS);
}
```
a.\(\quad \) PID \(=71\)(child) idata \(=200\) istack=400
PID=70(parent) idata=101 istack=201
b.\(\quad \mathrm{PID}=71\)(child) idata \(=0\) istack \(=0\)
PID=70(parent) idata=101 istack=201
c.\(\quad \) PID=71(child) idata=101 istack=201
PID=70(parent) idata=200 istack=400
d.\(\quad \mathrm{PID}=71\)(child) idata \(=0\) istack=0
PID=70(parent) idata \(=200\) istack=400
` ` ` 7 . What do you expect when you run the

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!