const shell = require('shelljs')
let cmd = shell.exec(`sleep 1m; echo a`, {async: true})
console.log(cmd.pid)
cmd.kill('SIGINT')
console.log(cmd)
结果:
2364
ChildProcess {
_events:
...
killed: true,
...
const shell = require('shelljs')
let cmd = shell.exec(`sleep 1m; echo a`, {async: true})
console.log(cmd.pid)
cmd.kill('SIGINT')
let isKilled = cmd.killed
console.log(isKilled)
cmd = shell.exec(`sleep 1s; echo b`, {async: true})
isKilled = cmd.killed
console.log(cmd.pid)
console.log(isKilled)
结果:
5681
true
5683
false
b
1m 后还是会输出 a,说明没有被杀死吗?