Node.js子进程通过SIGTERM退出

mit*_*man 7 linux child-process node.js

我正在使用Node 6.9生成一个子进程。

const child = require('child_process').execFile('command', args); 
child.stdout.on('data', (data) => {
    console.log('child:', data);
});
child.stderr.on('data', (data) => {
    console.log('child:', data);
});
child.on('close', (code, signal) => {
    console.log(`ERROR: child terminated. Exit code: ${code}, signal: ${signal}`);
});
Run Code Online (Sandbox Code Playgroud)

我的子进程运行了大约1m 30s,但是随后从Node.js程序中获得了以下输出:

ERROR: child terminated. Exit code: null, signal: SIGTERM
Run Code Online (Sandbox Code Playgroud)

什么终止了我的孩子进程,为什么?

编辑: 我添加了killSignal:'SIGILL'作为选项。

var child = require('child_process').execFile('geth', args, { killSignal: 'SIGILL'}); 
Run Code Online (Sandbox Code Playgroud)

现在,我得到了:

ERROR: go-ethereum terminated. Exit code: 2, signal: null
Run Code Online (Sandbox Code Playgroud)

mit*_*man 9

我找到了问题和解决方案。

来自https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_child_process_execfile_file_args_options_callback

maxBuffer stdout或stderr上允许的最大数据量(以字节为单位)-如果超出子进程被杀死(默认值:200 * 1024)

我可以将maxBuffer选项设置得更高。

childProcess.execFile('geth', args, { maxBuffer:  400 * 1024});
Run Code Online (Sandbox Code Playgroud)

似乎无法禁用该maxBuffer选项,即使将其设置为0也是如此。但这似乎是故意的。