Node.js子进程通过SIGTERM退出 [英] Node.js child process exits with SIGTERM

查看:131
本文介绍了Node.js子进程通过SIGTERM退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm spawning a child process using 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}`);
});

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

My child process runs for ~1m 30s but then I get this output from my Node.js program:

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

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

What terminates my child process and why?

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

I've added killSignal: 'SIGILL' as an option.

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

现在,我明白了:

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

推荐答案

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

I found the problem and a solution.

来自 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 largest amount of data (in bytes) allowed on stdout or stderr - if exceeded child process is killed (Default: 200*1024)

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

I can set the maxBuffer option higher.

childProcess.execFile('geth', args, { maxBuffer:  400 * 1024});

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

It seems you can't disable the maxBuffer option, not even by setting it to 0. But it seems to be on purpose.

这篇关于Node.js子进程通过SIGTERM退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆