ptg10805159
Appendix C Chapter 9 Solutions 923
8.6 The program in FigureC.10 creates a zombie.
#include "apue.h"
#ifdef SOLARIS
#define PSCMD "ps -a -o pid,ppid,s,tty,comm"
#else
#define PSCMD "ps -o pid,ppid,state,tty,command"
#endif
int
main(void)
{
pid_t pid;
if ((pid = fork()) < 0)
err_sys("fork error");
else if (pid == 0) /* child */
exit(0);
/* parent */
sleep(4);
system(PSCMD);
exit(0);
}
Figure C.10 Create a zombie and look at its status withps
Zombies areusually designated byps( 1 )with a status ofZ:
$./a.out
PID PPIDSTTCOMMAND
2369 2208Spts/2 -bash
7230 2369Spts/2 ./a.out
7231 7230Zpts/2 [a.out] <defunct>
7232 7230Spts/2 sh -c ps -o pid,ppid,state,tty,command
7233 7232Rpts/2 ps -o pid,ppid,state,tty,command
Chapter 9
9.1 Theinitprocess learns when a terminal user logs out, becauseinitis the
parent of the login shell and receives theSIGCHLDsignal when the login shell
terminates.
For a network login, however,initis not involved. Instead, the login entries in
theutmpandwtmpfiles, and their corresponding logout entries, areusually
written by the process that handles the login and detects the logout (telnetdin
our example).