ch3-zombie

Chapter_3     wait SIGCHLD







zombie.c     ALP, p. 60-61


#include <stdlib.h> // for exit()
#include <sys/types.h> // for pid_t
#include <unistd.h> // for fork(), sleep()

int main()
{
pid_t child_pid;

child_pid = fork (); /* Create a child process */
if (child_pid > 0) // parent
{sleep (60);} // 60 seconds
else // child
{exit (0);} // Exit immediately

return 0; // parent returns after 1 minute
}
/*
gcc zombie.c -o zombie
./zombie & // run in background
[1] 50064

ps -e -o pid,ppid,stat,cmd
PID PPID STAT CMD
1 0 Ss /sbin/init splash
......................
50037 1 Sl qterminal
50040 50037 Ss /bin/bash
50064 50040 S ./zombie
50065 50064 Z [zombie] <defunct>
50066 50040 R+ ps -e -o pid,ppid,stat,cmd

// after 1 minute:
ps -e -o pid,ppid,stat,cmd
......................
50368 50040 R+ ps -e -o pid,ppid,stat,cmd
[1]+ Done ./zombie

ps -e -o pid,ppid,stat,cmd
......................
50420 50040 R+ ps -e -o pid,ppid,stat,cmd
*/









Chapter_3     wait BACK_TO_TOP SIGCHLD



Comments

Popular posts from this blog

Contents