๐ก Signals
May 26, 2024 ยท View on GitHub
Windows do not use signals like Unix does.
Terminating processes
However processes can be terminated using the
taskkill
command. The taskkill project can
be used to do it from Node.js. fkill
builds on it to terminate processes on any OS.
Cross-platform signals
Which signals can be used is OS-specific:
process.kill()can only use the following signals on Windows:SIGINT,SIGTERM,SIGKILL,SIGQUITand0.process.on(signal)can be used on Windowscmd.exewith:SIGINT: but only when hittingCTRL-CSIGBREAK:CTRL-BREAK. However, this signal only works on Windows.SIGHUP: closing the window. The process is terminated after 10 seconds.SIGWINCH: resizing the terminal. This will only be triggered on Windows when the cursor moves on when a terminal in raw mode is used.
SIGPOLL,SIGPWRandSIGSTKFLTcan only be used on Linux.SIGINFOcan only be used on Mac.
Each signal has both an OS-agnostic name and an OS-specific integer constant.
process.kill()
can use either. It is possible to convert between both using
os.constants.signals.
However it is more cross-platform to use signal names instead of integer
constants.
Process groups
Using a negative argument with
process.kill()
to target a process group ID (as opposed to
a PID) does not work on Windows.
Summary
Use fkill to terminate processes.
Only use:
process.kill()withSIGINT,SIGTERM,SIGKILL,SIGQUITand0.process.on(signal)withSIGINT,SIGHUPandSIGWINCH.