Here is my updated code snippet
for (int i=0; i<30; i++){
printf("Forking\n");
tmpPid = fork();
switch(tmpPid)
{
case -1:
printf("Error");
break;
case 0:
printf("Fork success for proc %d\n", i);
//call some function
_exit(0)
break;
default:
printf("Fork succeed");
//store the pid in a vector
break;
}
}
//iterate through the vector and wait on each process.
// waitpid(vectorList[i], &exitStatus, WNOHANG)
Forking of almost 15-18 child process works fine. But for some process, the child code is not executed at all and the child process just hangs. (i,e fork() only returns child id but not zero). If i buy more time inside the for loop by calling some other dummy functions, then this problem is not seen. Can anyone tell me whats the problem ? Is it necessary to put delay between multiple forks ?
Thanks
case 0(for example, if it doesn't call_exit, that's probably your problem). Give us a complete, compilable, self-contained example that demonstrates the problem. - David Schwartzsome functionever returns, isn't this pretty much a fork bomb? - unwind