This cycle is expected to be busy, I think the wait call will take care of this. If so, how can this be done in order not to fulfill expectations?
id = fork();
for (i = 0; i < 20; i++)
{
switch (id)
{
case 0:
exit(0);
default:
{
if (children>=3) {
int s;
wait(&s);
children--;
}
children++;
id = fork();
}
}
}
source
share