I'm using Node.js v0.10.31 on Windows 8.1 x64. I noticed that for a process (a node.js or python script) that handles the SIGINT
handler, the handler is not called when the signal is sent from another node.js process by process.kill(PID, "SIGINT")
, and thus causing it to terminate. However I indeed verified that the handlers are called if the SIGINT is sent by pressing CTRL-C
in console.
Here's the Node.js script that handles SIGINT
(CoffeeScript):
process.on 'SIGINT', -> console.log "SIGINT handled"
process.stdin.pipe(process.stdout)
console.log "PID: #{process.pid}"
Console Output:
PID: 6916
SIGINT handled (this happens when pressing ctrl-c in console)
SIGINT handled (this happens when pressing ctrl-c in console)
# process terminates when another process calls process.kill(6916, 'SIGINT')
And here's a python script that handles SIGINT
, which is also killed unconditionally by node.js process.kill(PID, 'SIGINT')
:
from signal import signal, SIGINT
import os
import time
def handler(signum, frame):
print "signal handled:", signum,
raise KeyboardInterrupt
signal(SIGINT, handler)
print "PID: ", os.getpid()
while True:
try:
time.sleep(1e6)
except KeyboardInterrupt:
print " KeyboardInterrupt handled"
Console output:
PID: 6440
signal handled:2 KeyboardInterrupt handled (this happens when pressing ctrl-c in console)
signal handled:2 KeyboardInterrupt handled (this happens when pressing ctrl-c in console)
# process terminated by another node.js script's process.kill(6440, 'SIGINT')
Why isn't the handler called?