增加停止指定命令接口

This commit is contained in:
whyour
2023-05-01 22:56:47 +08:00
parent 8db997abe8
commit 0af687f781
5 changed files with 42 additions and 8 deletions
+3 -4
View File
@@ -496,10 +496,9 @@ export async function killTask(pid: number) {
}
export async function getPid(name: string) {
let taskCommand = `ps -ef | grep "${name}" | grep -v grep | awk '{print $1}'`;
const execAsync = promisify(exec);
let pid = (await execAsync(taskCommand)).stdout;
return Number(pid);
const taskCommand = `ps -eo pid,command | grep "${name}" | grep -v grep | awk '{print $1}' | head -1 | xargs echo -n`;
const pid = await promiseExec(taskCommand);
return pid ? Number(pid) : undefined;
}
interface IVersion {