2017-04-13 126 views
2

我使用節點6.9產生子進程。Node.js子進程使用SIGTERM退出

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之間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 
+0

「獨立」意味着在容器內但不是由Node產生,還是在容器外產生,但由Node產生? – Ryan

+0

嗨瑞安,對不起,我說得更清楚。在容器內但不會產生節點 – mitchkman

+1

我不認爲'args'具有'timeout'屬性?如果你通過Object.assign({},args,{killSignal:'SIGILL'})',信號是否改變? – Ryan

回答

3

我發現這個問題和解決方案。

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,但它似乎是故意的。

+0

我認爲當我使用「進度通知」作爲子進程運行程序時,發生在我身上的是同樣的事情。運行一段時間之後,Node節點運行。估計緩衝區大小應該有多大似乎很棘手。在我看來,一個好的通用解決方案是避免運行記錄過多信息的程序。 – Jackson