spawning a child by double forking

Jeff Lawhorn jeffl at berick.uucp
Wed Jul 5 01:42:24 AEST 1989


]  Thus far, two people have suggested that one way to prevent zombie
]processes from building up is to fork twice instead of once when
]starting a child -- the child of the first fork forks again and then
]immediately exits.  The "grandchild" which results is inherited by
]init, which takes care of cleanup, and the parent therefore doesn't
]have to worry about cleaning up.

There is a better way to do this.  Have the parent ignore the
signal SIGCLD.  My man page for signal states:

   The SIGCLD affects two other system cals (wait(2), and exit(2))
   in the following ways:

   wait	If the func value of SIGCLD is set to SIG_IGN and a wait
	is executed, the wait will block until all of the calling
	process's child processes terminate; it will then return
	a value of -1 with errno set to ECHILD.

   exit	If in the exiting process's parent process the func value
	of SIGCLD is set to SIG_IGN, the exiting process will not
	create a zombie process.

It seems to me that this is exactly what you want.  If at some
future time you want to know whan the child goes away, all you
have to do is change your handling of SIGCLD.

--

Jeff Lawhorn                 I know I had a pithy quote sitting 
jeffl at berick.uucp            around here somewhere...
ucsd!sdsu!berick!jeffl       
-- 

Jeff Lawhorn                 I know I had a pithy quote sitting 
jeffl at berick.uucp            around here somewhere...
ucsd!sdsu!berick!jeffl       



More information about the Comp.unix.questions mailing list