marmistrz
marmistrz

Reputation: 6392

SIGCHLD not delivered when a process exits

I need to detect when one of my background processes exits. Hence, I installed a trap. run_gui and run_ai1 are simple exec functions.

run_gui & gui_pid=$!
run_ai1 & ai1_pid=$!
trap 'echo foo' SIGCHLD
while true; do
    echo "Started the loop"
    while true; do
        read -u $ai1_outfd line || echo "Nothing read"
        if [[ $line ]]; then
            : # Handle this
        fi
    done
    while true; do
        read -u $gui_outfd line || echo "nothing read"
        if [[ $line ]]; then
            : # Handle this
        fi
    done
done

When I close the GUI, nothing happens. The echo foo command is executed only if I press ctrl+c.

Why do I miss the SIGCHLD?

Upvotes: 3

Views: 1060

Answers (1)

Cyrus
Cyrus

Reputation: 88601

Non-interactive shells don't enable job control by default. See if putting 'set -o monitor' at the beginning of the script produces the results you want.

Source: Chet Ramey, GNU Bash's maintainer

Upvotes: 5

Related Questions