简体   繁体   中英

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. 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. However, the docs tell me that process.kill only sends an exit signal. 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. 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

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.

Signal names are strings such as 'SIGINT' or 'SIGHUP'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM