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.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/platform.py b/packages/meshbay-node/src/meshbay_node/platform.py
index 88db83d..c0e4d00 100644
--- a/packages/meshbay-node/src/meshbay_node/platform.py
+++ b/packages/meshbay-node/src/meshbay_node/platform.py
@@ -397,6 +397,35 @@ def autostart_end() -> None:
subprocess.run(argv, capture_output=True)
+def node_pids() -> list[int]:
+ """Every meshbay-node.exe running, in any session, except this process and
+ its parent (the CLI is meshbay-node.exe too). Empty off Windows.
+
+ What says whether a node is still there after a stop: its control API
+ closes first, so a process that has not exited yet answers nothing and
+ used to count as gone.
+ """
+ if sys.platform != "win32":
+ return []
+ r = subprocess.run(["tasklist", "/FI", f"IMAGENAME eq {NODE_IMAGE}", "/NH", "/FO", "CSV"],
+ capture_output=True, text=True)
+ mine = {os.getpid(), os.getppid()}
+ pids = []
+ for line in r.stdout.splitlines():
+ cells = [c.strip('"') for c in line.split('","')]
+ if len(cells) > 1 and cells[1].isdigit() and int(cells[1]) not in mine:
+ pids.append(int(cells[1]))
+ return pids
+
+
+def kill_pid(pid: int) -> None:
+ """Force-stop one process and its children (its ffmpeg transcodes). Reaches
+ this session only, unless the caller is elevated. Windows only: systemd
+ stops the node everywhere else."""
+ if sys.platform == "win32":
+ subprocess.run(["taskkill", "/F", "/T", "/PID", str(pid)], capture_output=True)
+
+
# ── Service mode (Windows, opt-in at install time) ───────────────────────────
#
# The Startup-folder .vbs above only ever runs after *this* user signs in. A