( appName: string, executor: CommandExecutor, )
| 50 | const MAC_PID_INTERVAL_MS = 100; |
| 51 | |
| 52 | async function resolveProcessId( |
| 53 | appName: string, |
| 54 | executor: CommandExecutor, |
| 55 | ): Promise<number | undefined> { |
| 56 | const start = Date.now(); |
| 57 | while (Date.now() - start < MAC_PID_TIMEOUT_MS) { |
| 58 | try { |
| 59 | const pgrepResult = await executor(['pgrep', '-x', appName], 'Get Process ID', false); |
| 60 | if (pgrepResult.success && pgrepResult.output) { |
| 61 | const pid = parseInt(pgrepResult.output.trim().split('\n')[0], 10); |
| 62 | if (!isNaN(pid)) { |
| 63 | return pid; |
| 64 | } |
| 65 | } |
| 66 | } catch { |
| 67 | // not visible yet |
| 68 | } |
| 69 | await new Promise((resolve) => setTimeout(resolve, MAC_PID_INTERVAL_MS)); |
| 70 | } |
| 71 | return undefined; |
| 72 | } |
no test coverage detected