Zombies from forked thread process. Why?

Dave Cinege dcinege at psychosis.com
Wed Aug 15 11:53:01 EDT 2001


Linux 2.4, Debian 2.2/Redhat 7.1 Python 2.1.1 compiled from source.

I have a daemon process that watches a directory for files. When
some appear it decides what to do with them and then spawns a 
processor to handle them. To be speedy it detaches (forks) a processor
for each 'section'. Eveything run perfect, except that when the processor 
process returns it leaves a zombie in the process tree:
IE
root  29065  0.0  0.0  0  0 ?   Z  11:40 0:00 [mss_snort-updat <defunct>]

This is only when invoked by my daemon and not directly by hand.

This is probably all moot as the processors are python based and in
the future I'll just create a thread for each one that is spawned
instead of a seperate process. However I'd like to understand why
this is going on.

Rough code chunk:
----------------------------------------
threadsdie = 0	

def filewatch():
	for hostdir in processordict.keys():
		...
		if os.fork() == 0:  #same result with os.spawnv
			threadsdie = 1 # Thought it might fix it somehow.
			os.execl(mss.snortprocessor,'snortprocessor',tmpdir)
def filewatch_thread():
	while not threadsdie:
		filewatch()
def main():	
	t0 = threading.Thread(None,filewatch_thread(),None,())
	t0.start()
	
	while not threadsdie:
		t0.join()
		time.sleep(2)	# Never race
		t0.run()




More information about the Python-list mailing list