我正在使用 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
最佳答案
我找到了问题和解决方案。
maxBuffer largest amount of data (in bytes) allowed on stdout or stderr - if exceeded child process is killed (Default: 200*1024)
我可以将 maxBuffer
选项设置得更高。
childProcess.execFile('geth', args, { maxBuffer: 400 * 1024});
似乎您无法禁用 maxBuffer
选项,即使将其设置为 0 也无法禁用。但这似乎是故意的。
关于Node.js 子进程以 SIGTERM 退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43401872/