i have one, bad smelling problem :(
i have this code:
int main()
{
pid_t child, parent;
int status=0;
int i;
printf("parent = %d\n", getpid());
for(i=1; i<=5; i++){
if( (child = fork()) == 0){
sleep(i);
printf("i=%d, %d\n",i, getpid());
}
}
wait(0);
while( (parent = wait(&status)) > 0){
printf("Exit = %d, child = %d\n", status/256, parent);
}
}
and output is similar to:
1, 21320
2, 21321
Exit = 0, child = 21321
3, 21322
Exit = 0, child = 21322
4, 21323
Exit = 0, child = 21323
5, 21324
Exit = 0, child = 21324
And i think that wait(0) not waiting for all subprocess but only wait for first exit and write all (Exit = ...).
Is any way to do this:
1, 21320
2, 21321
3, 21322
4, 21323
5, 21324
Exit = 0, child = 21320
Exit = 0, child = 21321
Exit = 0, child = 21322
Exit = 0, child = 21323
Exit = 0, child = 21324
?