修复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) {
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);
try {
let pid = (await execAsync(taskCommond)).stdout;
let pid = (await execAsync(taskCommand)).stdout;
if (pid) {
pid = (await execAsync(`pstree -p ${pid}`)).stdout;
} else {
return;
}
const pids = pid.match(/\d+/g);
const pids = pid.match(/\(\d+/g);
const killLogs = [];
for (const id of pids) {
const c = `kill -9 ${id}`;
const c = `kill -9 ${id.slice(1)}`;
const { stdout, stderr } = await execAsync(c);
if (stderr) {
killLogs.push(stderr);