d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > How Many New Process Does Each Fork() Create > C
Add Reply New Topic New Poll
Member
Posts: 20,928
Joined: Mar 18 2009
Gold: 435,910.13
Sep 22 2013 02:29am
Code
/* Program A */
int main()
{
int i = 3;
int pid;
while(i > 0) {
pid = fork();
if (pid > 0) {
exit(0);
} else {
i--;
}
}
}


Code
/* Program B */
int main()
{
int i = 3;
int pid;
while(i > 0) {
pid = fork();
if (pid > 0) {
i--;
exit(0);
} else {
// nothing
}
}
}

For each say how many new processes it creates (not counting the initial process).
i got 3 for A and unending for B , is that correct?
Banned
Posts: 4,377
Joined: Dec 25 2012
Gold: 13,953.01
Warn: 10%
Sep 22 2013 03:37am
Looks good to me. Children should all exit the loop in A, so 3 children are created. In B, the children are stuck in the while loop.
Member
Posts: 20,928
Joined: Mar 18 2009
Gold: 435,910.13
Sep 22 2013 05:58am
Quote (zackill4 @ Sep 21 2013 11:37pm)
Looks good to me. Children should all exit the loop in A, so 3 children are created. In B, the children are stuck in the while loop.


alright awesome thnx
already submitted but it's only 10% per day so if i got them wrong still worth it to resub

This post was edited by bakalolo on Sep 22 2013 05:59am
Go Back To Homework Help Topic List
Add Reply New Topic New Poll