From: kapul on
Hello!

I've got a question regarding signal sending and/or handing in child
processes of bash script.

The script simply executes itself as a subprocess:

$ cat script
#!/bin/bash
#set -x
set -e
set -u

if [ "$#" = 0 ]
then
# Run N tasks
N=3
child_pids=""
for i in $(seq 1 $N)
do
$0 child &
child_pids="$child_pids $!"
sleep 0.1
done
trap "set -x; kill -INT $child_pids; wait; exit 1" INT
wait
exit 0
fi

if [ "$1" = "child" ]
then
for n in $(seq 0 1000)
do

echo "* trying $n ..."
trap "set -x; echo \"** SIGINT: Deleting intermediate files ...
\";
exit 1" INT

echo "* Doing $n"

sleep $((5 + $RANDOM / 10000))
done
fi

When script is run with no arguments:

$ ./script

it executes N (N=3) subprocesses in the background.

Parent process as well as all subprocesses sets own handlers (using
trap) on INT signal. When INT signal
(^C or kill -INT PID) is sent to process it's not propagated to
subprocesses! Why??
What is interesting that even INT signal sent directly to subprocesses
(using kill) is ignored.

What's happening here, any ideas? Please help ;)

M.
From: Ersek, Laszlo on
On Tue, 6 Jul 2010, kapul wrote:

> I've got a question regarding signal sending and/or handing in child
> processes of bash script.

> for i in $(seq 1 $N)
> do
> $0 child &
> child_pids="$child_pids $!"
> sleep 0.1
> done
> trap "set -x; kill -INT $child_pids; wait; exit 1" INT
> wait
> exit 0

I probably won't be able to answer your question (which I snipped, sorry),
but the last time I wrote something like this (I sort of did in bash what
GNU xargs -P does), I think I had to toggle "monitor mode" (job control).
See "set -m/+m".

If you care for the script, I might post it here (it's no secret just
probably too raw for public consumption or whatever).

lacos
From: kapul on
Hi!

> I probably won't be able to answer your question (which I snipped, sorry),
> but the last time I wrote something like this (I sort of did in bash what
> GNU xargs -P does), I think I had to toggle "monitor mode" (job control).
> See "set -m/+m".

No, switching job control did not help :(

I've noticed that using different signal (TERM, USR1) solves the
problem.
So this blocking issue is related only to INT signal

M.