Node.js NodeJS子进程终止

Node.js NodeJS子进程终止,node.js,linux,windows-subsystem-for-linux,Node.js,Linux,Windows Subsystem For Linux,是否有方法确保子进程已被终止 我目前拥有以下代码: let p = child_process.spawn(app, args); ... try{ p.kill('SIGKILL'); } catch(e) { console.error("Killing process exception:", e); } job = setInterval( () => { if(p.killed || timeout === true){ clearInterval(jo

是否有方法确保子进程已被终止

我目前拥有以下代码:

let p = child_process.spawn(app, args);
...
try{
   p.kill('SIGKILL');
} catch(e) {
   console.error("Killing process exception:", e);
}

job = setInterval( () => {
  if(p.killed || timeout === true){
    clearInterval(job);
    callback();
  }
}, 100);
setTimeout( () => {
  console.log("Killing process timeout!");
  timeout = true;
}, 1000);
我定期(100毫秒周期)检查终止信号是否已正确发送到进程,在那一刻,我假设进程已终止;但是,为了确保进程没有被锁定,我将超时设置为1秒

多次触发超时,与等待1秒或10秒无关

下面的代码是在linux中执行的;如果在WSL中工作,那么一切似乎都正常工作