I need a mechanism to fork child processes and all child processes should connect to a server.but the number of child processes should be limited(for ex:50)
Here's my pseudo, but I cant figure out how to limit the child process number. Should I use a semaphore? or what?
for(;;)
{
pid=fork();
switch(pid)
{
case -1:
perror("fork");
break;
case 0:
Job();
sleep(5);
exit(0);
break;
default:
sleep(3);
break;
}
}
PS: i use Linux.