70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
31 lines
702 B
TypeScript
31 lines
702 B
TypeScript
import childProcess from "node:child_process";
|
|
|
|
interface Process {
|
|
pid: string;
|
|
cmd: string;
|
|
}
|
|
|
|
function getProcesses(): Process[] {
|
|
return childProcess
|
|
.execSync("ps -e | awk '{print $1,$4}'", { encoding: "utf8" })
|
|
.trim()
|
|
.split("\n")
|
|
.map((line) => {
|
|
const [pid, cmd] = line.split(" ");
|
|
return { pid, cmd };
|
|
});
|
|
}
|
|
|
|
function getProcessCwd(pid: string | number) {
|
|
return childProcess
|
|
.execSync(`lsof -p ${pid} | awk '$4=="cwd" {print $9}'`, {
|
|
encoding: "utf8",
|
|
})
|
|
.trim();
|
|
}
|
|
export function getStartedWorkerdProcesses(cwd: string): Process[] {
|
|
return getProcesses()
|
|
.filter(({ cmd }) => cmd.includes("workerd"))
|
|
.filter((c) => getProcessCwd(c.pid).includes(cwd));
|
|
}
|