2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-07-29 17:18:04 +05:30
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
|
|
|
if (common.isWindows) {
|
2015-08-02 19:36:43 +05:30
|
|
|
console.log('1..0 # Skipped: SIGUSR1 and SIGHUP signals are not supported');
|
|
|
|
return;
|
2012-03-05 13:20:13 -08:00
|
|
|
}
|
2011-08-23 23:42:23 -07:00
|
|
|
|
2010-12-05 01:45:52 +03:00
|
|
|
console.log('process.pid: ' + process.pid);
|
2009-10-14 17:56:12 -04:00
|
|
|
|
2016-01-13 21:42:45 +01:00
|
|
|
let first = 0;
|
|
|
|
let second = 0;
|
2009-10-14 17:56:12 -04:00
|
|
|
|
2011-02-21 19:31:01 -05:00
|
|
|
var sighup = false;
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('SIGUSR1', function() {
|
2010-12-05 01:45:52 +03:00
|
|
|
console.log('Interrupted by SIGUSR1');
|
2009-10-14 17:56:12 -04:00
|
|
|
first += 1;
|
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('SIGUSR1', function() {
|
2009-10-14 17:56:12 -04:00
|
|
|
second += 1;
|
2010-12-05 01:45:52 +03:00
|
|
|
setTimeout(function() {
|
|
|
|
console.log('End.');
|
2009-10-14 17:56:12 -04:00
|
|
|
process.exit(0);
|
|
|
|
}, 5);
|
|
|
|
});
|
|
|
|
|
2010-12-04 16:11:57 -08:00
|
|
|
var i = 0;
|
2010-12-05 01:45:52 +03:00
|
|
|
setInterval(function() {
|
|
|
|
console.log('running process...' + ++i);
|
2009-10-14 17:56:12 -04:00
|
|
|
|
|
|
|
if (i == 5) {
|
2010-12-05 01:45:52 +03:00
|
|
|
process.kill(process.pid, 'SIGUSR1');
|
2009-10-14 17:56:12 -04:00
|
|
|
}
|
|
|
|
}, 1);
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
// Test on condition where a watcher for SIGNAL
|
2011-02-21 19:31:01 -05:00
|
|
|
// has been previously registered, and `process.listeners(SIGNAL).length === 1`
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('SIGHUP', function() {});
|
2011-02-21 19:31:01 -05:00
|
|
|
process.removeAllListeners('SIGHUP');
|
2015-05-19 13:00:06 +02:00
|
|
|
process.on('SIGHUP', function() { sighup = true; });
|
2011-02-21 19:31:01 -05:00
|
|
|
process.kill(process.pid, 'SIGHUP');
|
2009-10-14 17:56:12 -04:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('exit', function() {
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(1, first);
|
|
|
|
assert.equal(1, second);
|
2011-02-21 19:31:01 -05:00
|
|
|
assert.equal(true, sighup);
|
2009-10-14 17:56:12 -04:00
|
|
|
});
|