How To Avoid SIGCHLD error In Bash Script That Uses GNU Parallel

醉酒当歌 提交于 2019-12-22 08:31:46

问题


I'm running a script.sh in a loop. The script contains a parallel wget command. I'm getting the following error:

Signal SIGCHLD received, but no signal handler set.

The loop looks like this:

for i in {1..5}; do /script.sh; done

And the line that is causing the error looks like this (omitting options and settings):

cat file.txt | parallel -j15 wget

Research:

I'm not an expert with GNU Parallel, but the script seems to work fine most of the time except when I get the error above. While looking up SIGCHLD, I learned that running parallel can create "zombie processes" and sometimes, we need to "reap" these processes. Also, I found that you can kill processes because sometimes they can take up all the available connections.

Trying To Understand:

However, I don't know what is causing the issue in the first place. Is it my parallels? Am I not "reaping" processes? Should I be killing processes explicitly? Is it because I am running a parallel script in a loop?

My question:

How can I solve the SIGCHLD error?

If you have any experience with this, your insight is greatly appreciated.


回答1:


I think this might be a bug in parallel. There is a point in the code where the author is deleting the sigchld handler, presumably as a way of ignoring the signal. The perl documentation is silent on the effect that would have, suggesting to me that the result will be platform or implementation dependent and unreliable. The proper way to ignore a signal is to set the handler to "INGORE". I suggest trying version 20150222, an older version which does have this questionable code.




回答2:


(This is just a comment, but too long for comment).

So far no one have been able to reproduce the bug reliably. See if you can make an MCVE https://stackoverflow.com/help/mcve. If the IGNORE suggestion solves the issue, then the fix should be to change line 4361 in parallel from:

    delete $SIG{CHLD};

into:

    $SIG{CHLD} = 'IGNORE';

Let us know if that helped, so it can be put into next version if it works.



来源:https://stackoverflow.com/questions/39754323/how-to-avoid-sigchld-error-in-bash-script-that-uses-gnu-parallel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!