aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/platform.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/platform.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/platform.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/platform.py b/packages/meshbay-node/src/meshbay_node/platform.py
index 09397a2..2255036 100644
--- a/packages/meshbay-node/src/meshbay_node/platform.py
+++ b/packages/meshbay-node/src/meshbay_node/platform.py
@@ -226,6 +226,14 @@ def _startup_vbs() -> Path:
def _pid_alive(pid: int) -> bool:
"""Whether a process with this pid exists, in any session (tasklist lists
session 0 too, where a service-mode daemon runs; opening it would not)."""
+ if sys.platform != "win32":
+ # A zombie counts as gone: it has exited, and only its parent has not
+ # reaped it yet -- os.kill(pid, 0) would still find it.
+ try:
+ stat = Path(f"/proc/{pid}/stat").read_text(encoding="ascii")
+ except OSError:
+ return False
+ return stat.rsplit(")", 1)[1].split()[0] != "Z"
r = subprocess.run(["tasklist", "/FI", f"PID eq {pid}", "/NH", "/FO", "CSV"],
capture_output=True, text=True)
return f'"{pid}"' in r.stdout