File size: 2,295 Bytes
343eed9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
"""
scripts/list_started_processes.py

Utility to list the processes that were started by ``start_all.py``.
It looks for the command‑line strings that ``start_all.py`` uses to launch
the AI backend, Ollama, the FastAPI dashboard and the desktop shortcut.

Run it after ``python start_all.py``:

    python scripts/list_started_processes.py
"""

import sys
import os
from pathlib import Path

# psutil gives us a cross‑platform way to inspect running processes.
try:
    import psutil
except ImportError:
    print("[*] Installing psutil …")
    import subprocess
    subprocess.check_call([sys.executable, "-m", "pip", "install", "psutil"])
    import psutil

# ----------------------------------------------------------------------
# Identifiers that match the commands used in start_all.py
# ----------------------------------------------------------------------
IDENTIFIERS = [
    # AI backend (StabilityMatrix or generic python backend)
    "StabilityMatrix",
    "START_AI_BACKEND",
    # Ollama service
    "ollama",
    # FastAPI dashboard server
    "dashboard_server.py",
    # Desktop shortcut (just for completeness – not a process)
    "DARKMEDIA-X STUDIO",
]

def is_match(proc):
    """Return True if any identifier appears in the process name or cmdline."""
    try:
        name = proc.name().lower()
        cmd = " ".join(proc.cmdline()).lower()
        for ident in IDENTIFIERS:
            ident_lc = ident.lower()
            if ident_lc in name or ident_lc in cmd:
                return True
    except (psutil.NoSuchProcess, psutil.AccessDenied):
        return False
    return False

def main():
    print("\n=== Processes started by start_all.py ===\n")
    matches = [p for p in psutil.process_iter(['pid', 'name', 'cmdline']) if is_match(p)]

    if not matches:
        print("⚠️  No matching processes were found. Did you run start_all.py?")
        return

    for proc in matches:
        try:
            pid = proc.pid
            name = proc.name()
            cmd = " ".join(proc.cmdline())
            print(f"[{pid}] {name}")
            print(f"    cmd: {cmd}")
        except (psutil.NoSuchProcess, psutil.AccessDenied):
            continue

    print("\n=== End of list ===\n")

if __name__ == "__main__":
    main()