简体   繁体   English

Node.js 子进程以 SIGTERM 退出

[英]Node.js child process exits with SIGTERM

I'm spawning a child process using Node 6.9.我正在使用 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}`);
});

My child process runs for ~1m 30s but then I get this output from my Node.js program:我的子进程运行了约 1m 30 秒,但随后我从我的 Node.js 程序中获得了以下输出:

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

What terminates my child process and why?什么终止了我的子进程,为什么?

Edit: I've added killSignal: 'SIGILL' as an option.编辑:我添加了 killSignal: 'SIGILL' 作为选项。

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

Now, I get this:现在,我明白了:

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

I found the problem and a solution.我找到了问题和解决方案。

From https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_child_process_execfile_file_args_options_callback来自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 在 stdout 或 stderr 上允许的最大数据量(以字节为单位) - 如果超过,则杀死子进程(默认值:200*1024)

I can set the maxBuffer option higher.我可以将maxBuffer选项设置得更高。

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

It seems you can't disable the maxBuffer option, not even by setting it to 0. But it seems to be on purpose.似乎您无法禁用maxBuffer选项,即使将其设置为 0 也不行。但这似乎是故意的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM