2017-09-25 11:28:00 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
2025-01-22 14:19:38 -08:00
|
|
|
if (common.isWindows) {
|
2017-09-25 11:28:00 +02:00
|
|
|
common.skip('Sending signals with process.kill is not supported on Windows');
|
2025-01-22 14:19:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
const { isMainThread } = require('worker_threads');
|
|
|
|
|
|
|
|
if (!isMainThread) {
|
2018-05-18 01:20:25 +02:00
|
|
|
common.skip('No signal handling available in Workers');
|
2025-01-22 14:19:38 -08:00
|
|
|
}
|
2017-09-25 11:28:00 +02:00
|
|
|
|
|
|
|
process.once('SIGINT', common.mustCall((signal) => {
|
|
|
|
assert.strictEqual(signal, 'SIGINT');
|
|
|
|
}));
|
|
|
|
|
|
|
|
process.kill(process.pid, 'SIGINT');
|
|
|
|
|
|
|
|
process.once('SIGTERM', common.mustCall((signal) => {
|
|
|
|
assert.strictEqual(signal, 'SIGTERM');
|
|
|
|
}));
|
|
|
|
|
|
|
|
process.kill(process.pid, 'SIGTERM');
|
|
|
|
|
|
|
|
// Prevent Node.js from exiting due to empty event loop before signal handlers
|
|
|
|
// are fired
|
|
|
|
setImmediate(() => {});
|