Files
eh-downloader/pid_check.ts
2024-05-31 14:24:57 +08:00

18 lines
583 B
TypeScript

import { exists } from "@std/fs/exists";
export async function check_running(pid: number | bigint) {
if (Deno.build.os == "windows") {
const cmd = new Deno.Command("tasklist.exe", {
args: ["/NH", "/FI", `pid eq ${pid}`],
stdout: "piped",
});
const c = cmd.spawn();
const o = await c.output();
if (o.code !== 0) return;
const s = (new TextDecoder()).decode(o.stdout);
return s.indexOf(`${pid}`) !== -1;
} else if (Deno.build.os == "linux") {
return await exists(`/proc/${pid}`);
}
}