Get the jcode server PID.
()
| 58 | sock.close() |
| 59 | |
| 60 | def get_server_pid(): |
| 61 | """Get the jcode server PID.""" |
| 62 | try: |
| 63 | result = subprocess.run( |
| 64 | ["lsof", "-U", "-a", "-c", "jcode"], |
| 65 | capture_output=True, text=True, timeout=5 |
| 66 | ) |
| 67 | for line in result.stdout.splitlines(): |
| 68 | if "jcode.sock" in line and "LISTEN" in line: |
| 69 | parts = line.split() |
| 70 | return int(parts[1]) |
| 71 | except: |
| 72 | pass |
| 73 | |
| 74 | # Fallback: find the oldest jcode process (likely the server) |
| 75 | try: |
| 76 | result = subprocess.run( |
| 77 | ["pgrep", "-o", "jcode"], capture_output=True, text=True, timeout=5 |
| 78 | ) |
| 79 | if result.stdout.strip(): |
| 80 | return int(result.stdout.strip().splitlines()[0]) |
| 81 | except: |
| 82 | pass |
| 83 | return None |
| 84 | |
| 85 | def proc_stat(pid): |
| 86 | """Get process stats from /proc.""" |
no test coverage detected