修复python3任务无法停止

This commit is contained in:
whyour 2021-10-23 23:22:08 +08:00
parent bcac3deb6e
commit 0bf4aec74e

View File

@ -241,19 +241,19 @@ export default class CronService {
} }
private async killTask(name: string) { private async killTask(name: string) {
let taskCommond = `ps -ef | grep "${name}" | grep -v grep | awk '{print $1}'`; let taskCommand = `ps -ef | grep "${name}" | grep -v grep | awk '{print $1}'`;
const execAsync = promisify(exec); const execAsync = promisify(exec);
try { try {
let pid = (await execAsync(taskCommond)).stdout; let pid = (await execAsync(taskCommand)).stdout;
if (pid) { if (pid) {
pid = (await execAsync(`pstree -p ${pid}`)).stdout; pid = (await execAsync(`pstree -p ${pid}`)).stdout;
} else { } else {
return; return;
} }
const pids = pid.match(/\d+/g); const pids = pid.match(/\(\d+/g);
const killLogs = []; const killLogs = [];
for (const id of pids) { for (const id of pids) {
const c = `kill -9 ${id}`; const c = `kill -9 ${id.slice(1)}`;
const { stdout, stderr } = await execAsync(c); const { stdout, stderr } = await execAsync(c);
if (stderr) { if (stderr) {
killLogs.push(stderr); killLogs.push(stderr);