How To Avoid SIGCHLD error In Bash Script That Use

2019-05-04 11:48发布

问题:

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.