| 100 | const verifiedDaemonPids = new Map<number, boolean>(); |
| 101 | |
| 102 | function getProcessCommandLine(pid: number): string { |
| 103 | if (process.platform === 'linux' && fs.existsSync('/proc')) { |
| 104 | return fs |
| 105 | .readFileSync(`/proc/${pid}/cmdline`, 'utf-8') |
| 106 | .replaceAll('\0', ' '); |
| 107 | } |
| 108 | if (IS_WINDOWS) { |
| 109 | return childProcess.execFileSync( |
| 110 | 'powershell.exe', |
| 111 | [ |
| 112 | '-NoProfile', |
| 113 | '-NonInteractive', |
| 114 | '-Command', |
| 115 | `(Get-CimInstance Win32_Process -Filter "ProcessId = ${pid}").CommandLine`, |
| 116 | ], |
| 117 | { |
| 118 | encoding: 'utf-8', |
| 119 | stdio: ['ignore', 'pipe', 'ignore'], |
| 120 | windowsHide: true, |
| 121 | }, |
| 122 | ); |
| 123 | } |
| 124 | return childProcess.execFileSync( |
| 125 | 'ps', |
| 126 | ['-p', String(pid), '-o', 'command='], |
| 127 | { |
| 128 | encoding: 'utf-8', |
| 129 | stdio: ['ignore', 'pipe', 'ignore'], |
| 130 | }, |
| 131 | ); |
| 132 | } |
| 133 | |
| 134 | function isDaemonProcess(pid: number): boolean { |
| 135 | const cached = verifiedDaemonPids.get(pid); |