Skip to content

Instantly share code, notes, and snippets.

@ETiV
Created April 8, 2014 18:14
Show Gist options
  • Save ETiV/10165657 to your computer and use it in GitHub Desktop.
Save ETiV/10165657 to your computer and use it in GitHub Desktop.
测试 NodeJS 支持的 kill signals
/**
* Created by ETiV on 4/9/14.
*/
var target_pid = 26263;
var signals = ['SIGHUP',
'SIGINT',
'SIGQUIT',
'SIGILL',
'SIGTRAP',
'SIGABRT',
'SIGIOT',
'SIGBUS',
'SIGFPE',
// 'SIGKILL', // will raise error
// 'SIGUSR1', // will start debugger
'SIGSEGV',
'SIGUSR2',
'SIGPIPE',
'SIGALRM',
'SIGTERM',
'SIGCHLD',
'SIGCONT',
//'SIGSTOP', // will raise error
'SIGTSTP',
'SIGTTIN',
'SIGTTOU',
'SIGURG',
'SIGXCPU',
'SIGXFSZ',
'SIGVTALRM',
'SIGPROF',
'SIGWINCH',
'SIGIO',
'SIGSYS'];
for (var i = 0; i < signals.length; i++) {
process.kill(target_pid, signals[i]);
}
/**
* Created by ETiV on 4/9/14.
*/
console.log(process.pid);
var signals = ['SIGHUP',
'SIGINT',
'SIGQUIT',
'SIGILL',
'SIGTRAP',
'SIGABRT',
'SIGIOT',
'SIGBUS',
'SIGFPE',
// 'SIGKILL', // will raise error
// 'SIGUSR1', // will start debugger
'SIGSEGV',
'SIGUSR2',
'SIGPIPE',
'SIGALRM',
'SIGTERM',
'SIGCHLD',
'SIGCONT',
//'SIGSTOP', // will raise error
'SIGTSTP',
'SIGTTIN',
'SIGTTOU',
'SIGURG',
'SIGXCPU',
'SIGXFSZ',
'SIGVTALRM',
'SIGPROF',
'SIGWINCH',
'SIGIO',
'SIGSYS'];
for (var i = 0; i < signals.length; i++) {
console.log('install:', signals[i]);
try {
process.on(signals[i], (function () {
console.log('Got signal:', this.sig);
}).bind({sig: signals[i]}));
} catch (e) {
console.log(e);
}
}
process.stdin.resume(); // Start reading from stdin so we don't exit.
@ETiV
Copy link
Author

ETiV commented Apr 8, 2014

测试结果:

Got signal: SIGHUP
Got signal: SIGINT
Got signal: SIGILL
Got signal: SIGTRAP
Got signal: SIGABRT
Got signal: SIGIOT
Got signal: SIGFPE
Got signal: SIGUSR2
Got signal: SIGBUS
Got signal: SIGSEGV
Got signal: SIGPIPE
Got signal: SIGTERM
Got signal: SIGCHLD
Got signal: SIGALRM
Got signal: SIGTSTP
Got signal: SIGTTIN
Got signal: SIGTTOU
Got signal: SIGURG
Got signal: SIGXCPU
Got signal: SIGXFSZ
Got signal: SIGVTALRM
Got signal: SIGPROF
Got signal: SIGWINCH
Got signal: SIGSYS
Got signal: SIGIO

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