node/test/simple/test-signal-handler.js

36 lines
643 B
JavaScript
Raw Normal View History

2010-12-05 07:20:34 +08:00
var common = require('../common');
var assert = require('assert');
2010-12-05 06:45:52 +08:00
console.log('process.pid: ' + process.pid);
var first = 0,
second = 0;
2010-12-05 06:45:52 +08:00
process.addListener('SIGUSR1', function() {
console.log('Interrupted by SIGUSR1');
first += 1;
});
2010-12-05 06:45:52 +08:00
process.addListener('SIGUSR1', function() {
second += 1;
2010-12-05 06:45:52 +08:00
setTimeout(function() {
console.log('End.');
process.exit(0);
}, 5);
});
2010-12-05 08:11:57 +08:00
var i = 0;
2010-12-05 06:45:52 +08:00
setInterval(function() {
console.log('running process...' + ++i);
if (i == 5) {
2010-12-05 06:45:52 +08:00
process.kill(process.pid, 'SIGUSR1');
}
}, 1);
2010-12-05 06:45:52 +08:00
process.addListener('exit', function() {
assert.equal(1, first);
assert.equal(1, second);
});