• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (common.isWindows)
5  common.skip('Win32 does not support signals.');
6
7const assert = require('assert');
8const spawn = require('child_process').spawn;
9
10if (process.argv[2] !== '--do-test') {
11  // We are the master, fork a child so we can verify it exits with correct
12  // status.
13  process.env.DOTEST = 'y';
14  const child = spawn(process.execPath, [__filename, '--do-test']);
15
16  child.once('exit', common.mustCall(function(code, signal) {
17    assert.strictEqual(signal, 'SIGINT');
18  }));
19
20  return;
21}
22
23process.on('SIGINT', function() {
24  // Remove all handlers and kill ourselves. We should terminate by SIGINT
25  // now that we have no handlers.
26  process.removeAllListeners('SIGINT');
27  process.kill(process.pid, 'SIGINT');
28});
29
30// Signal handlers aren't sufficient to keep node alive, so resume stdin
31process.stdin.resume();
32
33// Demonstrate that signals are being handled
34process.kill(process.pid, 'SIGINT');
35