Node.js 子进程以 SIGTERM 退出

标签 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

最佳答案

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

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

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/

相关文章:

macos - 在 bash 脚本中重定向多个子进程的输出

javascript - 如何在 Next.js React Framework 中构建自定义/动态路由

javascript - 使用map 进行并行请求,使用promise.all 进行for 循环,然后

linux - docker 容器大小远大于实际大小

php - UTF-8贯穿始终

node.js - NodeJS exec/spawn stdout 在 8192 个字符处切断流

javascript - 测试 Express 中间件

javascript - 对象或对象数组

linux - Eclipse 的一个窗口中的 Bash shell

c - 继续从同一个父进程创建多个子进程