Main process index.js:
const childProcess = require('child_process');
console.log('started main');
const subprocess = childProcess.exec('node childProcess.js', (error, stdout, stderr) => {
console.log('error from child process:', error);
console.log('stdout from child process: .............');
console.log(stdout);
console.log(stderr);
console.log('stdout from child process - end: .............');
});
console.log('last line main');
subprocess.kill('SIGINT');
setTimeout(() => {
console.log('ended main');
}, 5000);
Child process childProcess.js:
const fs = require('fs');
console.log('child started');
process.on('SIGINT', () => {
console.log('child ending');
fs.writeFileSync('test1.txt', 'abc');
process.exit();
});
fs.writeFileSync('test0.txt', 'abc');
setTimeout(() => {
console.log('timeout ended');
}, 3000);
When I start node index.js in the terminal I get the following output:
started main
last line main
error from child process: { Error: Command failed: node childProcess.js
at ChildProcess.exithandler (child_process.js:272:12)
at ChildProcess.emit (events.js:127:13)
at maybeClose (internal/child_process.js:933:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
killed: true,
code: null,
signal: 'SIGINT',
cmd: 'node childProcess.js' }
stdout from child process: .............
child started
timeout ended
stdout from child process - end: .............
ended main
Meaning that SIGINT handler in child process is not triggered.
(Also text0.txt side-effect file gets created and text1.txt does not. I also tried without setTimeout in child, same thing. I managed to trigger SIGTERM in child by ending the child process in "system monitor" processes list.)
- Version: 9.6.1 and 10.10.0
- Platform: Ubuntu 16.04
- Subsystem: process, subprocess
Main process
index.js:Child process
childProcess.js:When I start
node index.jsin the terminal I get the following output:Meaning that SIGINT handler in child process is not triggered.
(Also text0.txt side-effect file gets created and text1.txt does not. I also tried without setTimeout in child, same thing. I managed to trigger SIGTERM in child by ending the child process in "system monitor" processes list.)