fork(), problems with multiple children
1st, the code :
//create child
for ( ii = 0; ii < nbEnfants; ++ii) {
if ((p = fork()) == 0) {
/** PROCESSUS CHILD here **/
EEcrireMp(ii);
//exit(0);
}
else {
/** PROCESSUS PARENT here **/
tabPidEnfants[ii] = p;
usleep(50000);
ELireMp(nbSect, nbEnfants);
}
}
What I want to do : Create only 20 child records then do the thing in the
"else".This code works only if I leave the "exit()" but I can't leave it
because I won't have anymore "concurency" and I need "concurency" :/ In
"EEcrireMp()", I use semaphore (initialized at 0), so I do +1 each time
this function is run(it writes in shared_memory). Then if the same value
is equal to 20, then the condition in the "ELireMp()" will be activated,
and I can read what the 20 children writes. So like I said, this works
only if the "exit()" is there. If I remove the "exit()", I have the
impression that my child creates another 20 child and one off the new
child creates himself other 20 child and etc ... :( ps : my computer
completely freezes if I run the program. Thanks
No comments:
Post a Comment