mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
chore: Add in the ability to kill the tree of processes
This commit is contained in:
@@ -47,6 +47,7 @@ const childProcess = {
|
|||||||
exec: promisify(CP.exec),
|
exec: promisify(CP.exec),
|
||||||
execFile: promisify(CP.execFile),
|
execFile: promisify(CP.execFile),
|
||||||
}
|
}
|
||||||
|
const cp = childProcess
|
||||||
|
|
||||||
export type ServiceInterfaceType = "ui" | "p2p" | "api"
|
export type ServiceInterfaceType = "ui" | "p2p" | "api"
|
||||||
|
|
||||||
@@ -262,7 +263,7 @@ export const createUtils = <
|
|||||||
return await answer
|
return await answer
|
||||||
} finally {
|
} finally {
|
||||||
for (const process of pids) {
|
for (const process of pids) {
|
||||||
overlay.exec(["kill", `-9`, String(process)])
|
cp.execFile("kill", [`-9`, String(process)]).catch((_) => {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -292,11 +293,11 @@ export const createUtils = <
|
|||||||
console.error("Bluj actually killing pid ", pids)
|
console.error("Bluj actually killing pid ", pids)
|
||||||
try {
|
try {
|
||||||
for (const process of pids) {
|
for (const process of pids) {
|
||||||
await overlay.exec(["kill", `-${signal}`, String(process)])
|
await cp.execFile("kill", [`-${signal}`, String(process)])
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
for (const process of pids) {
|
for (const process of pids) {
|
||||||
overlay.exec(["kill", `-9`, String(process)])
|
cp.execFile("kill", [`-9`, String(process)]).catch((_) => {})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -319,7 +320,7 @@ export const createUtils = <
|
|||||||
function noop(): void {}
|
function noop(): void {}
|
||||||
|
|
||||||
async function psTree(pid: number, overlay: Overlay): Promise<number[]> {
|
async function psTree(pid: number, overlay: Overlay): Promise<number[]> {
|
||||||
const { stdout } = await overlay.exec(["pstree", `-p`, String(pid)])
|
const { stdout } = await childProcess.exec(`pstree -p ${pid}`)
|
||||||
const regex: RegExp = /\((\d+)\)/g
|
const regex: RegExp = /\((\d+)\)/g
|
||||||
return [...stdout.toString().matchAll(regex)].map(([_all, pid]) =>
|
return [...stdout.toString().matchAll(regex)].map(([_all, pid]) =>
|
||||||
parseInt(pid),
|
parseInt(pid),
|
||||||
|
|||||||
Reference in New Issue
Block a user