This repository has been archived by the owner. It is now read-only.

child_process.kill only works once #1035

Closed
joshwilsdon opened this Issue May 11, 2011 · 1 comment

Comments

Projects
None yet
2 participants

It seems there's a .killed property which is being set on a child_process when you send child_process.kill even when the signal you're sending is not a terminal signal. For example:

var fs = require('fs');
var spawn = require('child_process').spawn;
var signalee;
var signalee_code = '' +
  "var sigcount1 = 0;\n" +
  "var sigcount2 = 0;\n\n" +
  "process.on('SIGUSR1', function () {\n" +
  "  console.log('Got SIGUSR1 #' + sigcount1++);\n" +
  "});\n\n" +
  "process.on('SIGUSR2', function () {\n" +
  "  console.log('Got SIGUSR2 #' + sigcount2++);\n" +
  "});\n\n" +
  "setTimeout(function() {\n" +
  "  console.log('Timeout');\n" +
  "}, 10000);\n";

fs.writeFileSync('/tmp/testme.' + process.pid, signalee_code, encoding='utf8');
signalee = spawn('node', ['/tmp/testme.' + process.pid]);

signalee.stdout.on('data', function (data) {
  console.log('signalee stdout: ' + data.toString().replace(/\s+$/g, ''));
});

signalee.on('exit', function (code) {
  console.log('child process exited with code ' + code);
  fs.unlinkSync('/tmp/testme.' + process.pid);
});

setInterval(function() {
  signalee.kill('SIGUSR1');
  process.kill(signalee.pid, 'SIGUSR2');
}, 1000);

will output:

signalee stdout: Got SIGUSR1 #0
signalee stdout: Got SIGUSR2 #0
signalee stdout: Got SIGUSR2 #1
signalee stdout: Got SIGUSR2 #2
signalee stdout: Got SIGUSR2 #3
signalee stdout: Got SIGUSR2 #4
signalee stdout: Got SIGUSR2 #5
signalee stdout: Got SIGUSR2 #6
signalee stdout: Got SIGUSR2 #7
signalee stdout: Got SIGUSR2 #8
signalee stdout: Got SIGUSR2 #9
signalee stdout: Timeout
child process exited with code 0
User defined signal 2

showing that the process.kill(, 'SIGUSR2') can be sent multiple times, but only the first child_process.kill('SIGUSR1') actually gets sent.

sh1mmer commented Oct 24, 2011

Enki:~/Code/node-scratch $ node kill.js 
signalee stdout: Got SIGUSR1 #0
signalee stdout: Got SIGUSR2 #0
signalee stdout: Got SIGUSR1 #1
Got SIGUSR2 #1
signalee stdout: Got SIGUSR1 #2
signalee stdout: Got SIGUSR2 #2
signalee stdout: Got SIGUSR1 #3
signalee stdout: Got SIGUSR2 #3
signalee stdout: Got SIGUSR1 #4
signalee stdout: Got SIGUSR2 #4
signalee stdout: Got SIGUSR1 #5
Got SIGUSR2 #5
signalee stdout: Got SIGUSR1 #6
signalee stdout: Got SIGUSR2 #6
signalee stdout: Got SIGUSR1 #7
signalee stdout: Got SIGUSR2 #7
signalee stdout: Got SIGUSR1 #8
signalee stdout: Got SIGUSR2 #8
signalee stdout: Got SIGUSR1 #9
signalee stdout: Got SIGUSR2 #9
signalee stdout: Timeout
child process exited with code 0

node.js:345
            process._kill(pid, startup.lazyConstants()[sig]);
                    ^
Error: ESRCH, No such process
    at EventEmitter.kill (node.js:345:21)
    at Timer.<anonymous> (/Users/sh1mmer/Code/node-scratch/kill.js:31:11)
    at Timer.ontimeout (timers.js:208:14)
Enki:~/Code/node-scratch $ 

Seems to work on HEAD.

@sh1mmer sh1mmer closed this Oct 24, 2011

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.