giampaolo / psutil

Cross-platform lib for process and system monitoring in Python
BSD 3-Clause "New" or "Revised" License
10.32k stars 1.39k forks source link

[OpenBSD, NetBSD] zombie process has no ctime (breaks is_running()) #2287

Closed giampaolo closed 1 year ago

giampaolo commented 1 year ago

Summary

Description

On OpenBSD and NetBSD, zombie processes have a creation time of 0.0. The example below shows how a process starts normally (so it has a ctime), then it turns into a zombie. This breaks is_running() and also has repercussions on __eq__ and __hash__, which is used to allow creating a set() of uniue Process() objects.

(Pdb) parent, zombie = self.spawn_zombie()
(Pdb) zombie
psutil.Process(pid=35360, name='python3.8', status='zombie', started='00:04:16')
(Pdb) psutil.Process(zombie.pid)
psutil.Process(pid=33393, name='python3.8', status='zombie', started='1970-01-01 00:00:00')
(Pdb) psutil.Process(zombie.pid).create_time()
0.0 
(Pdb) zombie.is_running()  # should be True
False