Node.js子进程退出SIGTERM

时间:2017-04-13 21:18:31

标签: node.js linux child-process

我正在使用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}`);
});

我的子进程运行大约1个30秒但是我从Node.js程序得到了这个输出:

ERROR: child terminated. Exit code: null, signal: SIGTERM

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

修改 我添加了killSignal:'SIGILL'作为选项。

var child = require('child_process').execFile('geth', args, { killSignal: 'SIGILL'}); 

现在,我明白了:

ERROR: go-ethereum terminated. Exit code: 2, signal: null

1 个答案:

答案 0 :(得分:5)

我发现了问题和解决方案。

来自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});

似乎你无法禁用maxBuffer选项,甚至不能将其设置为0.但它似乎是故意的。