Skip to content

Commit

Permalink
#428: tests (assumptions) for dealing with a zombie process; currentl…
Browse files Browse the repository at this point in the history
…y works on linux only
  • Loading branch information
giampaolo committed Oct 31, 2014
1 parent 7d41c28 commit f8e338c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions test/test_psutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -2100,16 +2100,23 @@ def test_zombie_process(self):
select.select([conn.fileno()], [], [], GLOBAL_TIMEOUT)
zpid = int(conn.recv(1024))
zproc = psutil.Process(zpid)
# Make sure we can re-instantiate the process after its
# status changed to zombie and at least be able to
# query its status.
# XXX should we also assume ppid should be querable?
call_until(lambda: zproc.status(), "ret == psutil.STATUS_ZOMBIE")
self.assertTrue(psutil.pid_exists(zpid))
# A zombie process should always be instantiable
zproc = psutil.Process(zpid)
# ...and at least its status always be querable
self.assertEqual(zproc.status(), psutil.STATUS_ZOMBIE)
# ...its parent should 'see' it
descendants = [x.pid for x in psutil.Process().children(
recursive=True)]
self.assertIn(zpid, descendants)
# XXX should we also assume ppid be usable? Note: this
# would be an important use case as the only way to get
# rid of a zombie is to kill its parent.
# self.assertEqual(zpid.ppid(), os.getpid())
# ...and all other APIs should be able to deal with it
self.assertTrue(psutil.pid_exists(zpid))
self.assertIn(zpid, psutil.pids())
self.assertIn(zpid, [x.pid for x in psutil.process_iter()])
finally:
if sock is not None:
sock.close()
Expand Down

0 comments on commit f8e338c

Please sign in to comment.