|
Hello,
You are getting zombies, because the child from childpids[0] isn't killed.
See in while(--count) : When count is 1 -> --count gives 0 and loop exits. The program "forget" to kill first child and when the father program closes, that child becomes a zombie.
You can replace the while loop with:
for(count-=1; count >= 0; count--) { ...
or something equivalent.
A note, I see you use vfork() for creating childrens.... which will always work fine in your example. However, its behaviour will become undefined when you will call other functions than execl after the fork, or modify other variables. Fork() would be safer for programs which are not using execl.
Hope it helps.
Best regards.
|