Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: Best way to prevent zombie processes Date: Mon, 1 Jun 2015 14:59:30 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 38 Message-ID: References: <87vbf8l9e7.fsf@Equus.decebal.nl> <87vbf88k0n.fsf@elektro.pacujo.net> NNTP-Posting-Host: 67-130-15-94.dia.static.qwest.net X-Trace: reader1.panix.com 1433170770 9637 67.130.15.94 (1 Jun 2015 14:59:30 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 1 Jun 2015 14:59:30 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) Xref: csiph.com comp.lang.python:91679 On 2015-05-31, Marko Rauhamaa wrote: > Cecil Westerhof : > >> At the moment I have the following code: >> os.chdir(directory) >> for document in documents: >> subprocess.Popen(['evince', document]) >> >> With this I can open several documents at once. But there is no way to >> know when those documents are going to be closed. This could/will lead >> to zombie processes. (I run it on Linux.) What is the best solution to >> circumvent this? >> >> I was thinking about putting all Popen instances in a list. And then >> every five minutes walk through the list and check with poll if the >> process has terminated. If it has it can be released from the list. >> Of-course I need to synchronise those events. Is that a good way to do >> it? > > If you don't care to know when child processes exit, you can simply > ignore the SIGCHLD signal: > > import signal > signal.signal(signal.SIGCHLD, signal.SIG_IGN) > > That will prevent zombies from appearing. Bravo! I've been writing Unix apps for 30 years, and I did not know that. Is this something recent[1], or have I somehow managed to avoid this useful bit of info for that long? [1] "Recent" of course being rather subjective and highly age-dependent. -- Grant Edwards grant.b.edwards Yow! How's it going in at those MODULAR LOVE UNITS?? gmail.com