Files
orca/src/main/pty-process-table-parser.ts
T
Neil 9b23bd6b6e fix(daemon): sweep descendants on graceful close of shells without launch metadata (#33317)
Graceful close (mobile pane, headless tab, worktree stop) of a shell without launch metadata now sweeps descendants on macOS/Linux, matching desktop tab close, while sparing the shell's own nohup/disown jobs (login-wrapper aware). Windows graceful plain-shell close is unchanged.

Fixes #16714
2026-10-25 01:04:00 -07:00

29 lines
912 B
TypeScript

export type ProcessTableRow = {
pid: number
ppid: number
pgid: number
/** Foreground process group of the row's terminal; 0 or -1 without one. */
tpgid?: number
/** Verbatim lstart; delayed SIGKILL also requires matching pgid and an unambiguous capture boundary. */
startedAt: string
}
export function parseProcessTable(psOutput: string): ProcessTableRow[] {
const rows: ProcessTableRow[] = []
for (const line of psOutput.split('\n')) {
// lstart contains spaces, so only the leading numeric columns are positional; tpgid is optional.
const match = line.match(/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(?:(-?\d+)\s+)?(\D.*?)\s*$/)
if (!match) {
continue
}
rows.push({
pid: Number(match[1]),
ppid: Number(match[2]),
pgid: Number(match[3]),
...(match[4] === undefined ? {} : { tpgid: Number(match[4]) }),
startedAt: match[5]
})
}
return rows
}