[英]Sync kill a non-child process in node
I would like to use node to synchronously close another process. 我想使用节点同步关闭另一个进程。 I do know the process ID.
我确实知道进程ID。 I need to be sure this process has exited before another process starts.
我需要确保此过程已经退出,然后再开始另一个过程。
Ideally it would look like: 理想的情况是:
await process.kill(pid);
where await
actually waits for the process to close. 实际在哪里
await
进程关闭。 However, the docs tell me that process.kill only sends an exit signal. 但是,文档告诉我process.kill仅发送退出信号。 It does not seem to wait for a return signal or some indication that the process is no longer running.
它似乎并不在等待返回信号或某种迹象表明该进程不再运行。
I see process.exit()
is not an option here because it doesn't take a process ID. 我看到
process.exit()
在这里不是选项,因为它没有进程ID。 In fact it seems somehow related to child processes - but I do find the docs tricky to understand. 实际上,它似乎与子进程有某种联系-但我确实很难理解这些文档。 The process I want to kill is not a child process.
我要杀死的进程不是子进程。
You can see here node js process kill 您可以在此处看到节点js 进程终止
process.on('SIGINT', () => {
//Do what is next when process got killed
});
process.kill(pid, 'SIGINT');
The process.kill() method sends the signal to the process identified by pid. process.kill()方法将信号发送到pid标识的进程。
Signal names are strings such as 'SIGINT' or 'SIGHUP' 信号名称是诸如“ SIGINT”或“ SIGHUP”之类的字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.