Open jzr-supove opened 1 year ago
Mmm. Yeah, PID 0 on Linux is not a user process. It's not present in /proc directory, so it cannot be queried, but some low kernel PIDs have PID 0 as their parent:
$ ps -eaf
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 ago03 ? 00:00:17 /sbin/init splash
root 2 0 0 ago03 ? 00:00:00 [kthreadd]
root 3 2 0 ago03 ? 00:00:00 [rcu_gp]
root 4 2 0 ago03 ? 00:00:00 [rcu_par_gp]
root 5 2 0 ago03 ? 00:00:00 [slub_flushwq]
I wonder what sort of process you created (psutil.Process(psutil.Process(os.getpid()).ppid()).kill()
) that it has PPID == 0. Perhaps you can provide more info?
With that said, there's not much psutil can do in this case, because /pid/0
namespace does not exist so we cannot query PID 0 or interact with it. Still, this kind of bothers me, because it creates an inconsistency on Linux (on all other UNIX platforms PID 0 is querable):
>>> psutil.Process(1).ppid()
0
>>> psutil.Process(1).parent()
>>>
>>> psutil.pid_exists(0)
False
Summary
Description
Program fragment:
Output:
Works ok in local machine (WSL 2): Output: