gpt4 book ai didi

Node.js 子进程以 SIGTERM 退出

转载 作者:IT王子 更新时间:2023-10-29 01:18:07 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com