修改杀死进程逻辑

This commit is contained in:
whyour 2022-02-19 22:54:27 +08:00
parent f71b3d0378
commit f0f2c6b537

View File

@ -226,9 +226,9 @@ export default class CronService {
const killLogs = [];
if (pids && pids.length > 0) {
// node 执行脚本时还会有10个子进程但是ps -ef中不存在所以截取前三个
pids = pids.slice(0, 3);
for (const id of pids) {
const c = `kill -9 ${id.slice(1)}`;
try {
const { stdout, stderr } = await execAsync(c);
if (stderr) {
killLogs.push(stderr);
@ -236,6 +236,9 @@ export default class CronService {
if (stdout) {
killLogs.push(stdout);
}
} catch (error: any) {
killLogs.push(error.message);
}
}
}
return killLogs.length > 0 ? JSON.stringify(killLogs) : '';