Given this C program:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void) {
pid_t pid;
if ((pid = fork()) >= 0) {
if (pid == 0) {
exit(0);
} else {
sleep(999);
}
}
return 0;
}
after running:
$ gcc -o zombie zombie.c
$ ./zombie &
$ ps -f
only the parent process is showing:
501 77474 74651 0 2:36PM ttys000 0:00.00 ./zombie
On Linux the same program shows this:
osboxes 6900 6835 0 13:37 pts/1 00:00:00 ./zombie
osboxes 6903 6900 0 13:37 pts/1 00:00:00 [zombie] <defunct>
Now, strangely, on OSX when starting more than one zombie
programs..
$ ./zombie &
$ ./zombie &
$ ps -f
.. the zombie processes (in brackets) show up:
501 77653 74651 0 2:39PM ttys000 0:00.00 ./zombie
501 77664 74651 0 2:39PM ttys000 0:00.00 ./zombie
501 77667 77664 0 2:39PM ttys000 0:00.00 (zombie)
What's the reason for this?