Neil Parker wrote:
> How about something like this:
>
> #!/bin/sh
> # foo.sh: an example script
> trap 'kill -HUP $!;exit 1' 1 2 3 15
> for i in foo bar baz
> do find /home/$i &
> wait
> done
> exit 0
>
> This makes sure the signal (if it's HUP, INT, QUIT, or TERM) propogates
> to the find command. The funny business with the "&" and the "wait" is
> so we can get at find's pid using "$!".
>
> Be careful of the trap command...in order to work, the first argument must
> be in SINGLE quotes.
I experimented with this ; i should perhaps mention that /bin/sh for
this script is /bin/dash, the Debian Almquist shell, a Bourne shell
clone derivative of NetBSD.
What i observe, is that trap is not trapping the signal to the parent
process.
#!/bin/sh
# foo.sh: an example script
trap 'echo Duuude! ' USR1
for i in foo bar baz
do find /home/$i &
wait
done
exit 0
$ ./foo.sh &
$ ps f
PID TTY STAT TIME COMMAND
123 pts/3 Ss 0:00 -bash
247 pts/3 S+ 0:00 \_ /bin/dash /home/prwade/foo.sh
420 pts/3 S+ 0:00 \_ /bin/dash /home/prwade/foo.sh
1337 pts/3 S+ 0:00 \_ /usr/bin/find
$ kill -USR1 247 # no output
$ kill -USR1 420
Duuude!
Perhaps the parent process is waiting for the subshell to complete
before it looks at signals.
I think Larry's idea of pgrep, together with a suggestion i got from
another source about killing the process group, may be the direction i
need to take ; i'm experimenting further.
--
On two occasions I have been asked [by members of Parliament!], 'Pray,
Mr. Babbage, if you put into the machine wrong figures, will the right
answers come out?' I am not able rightly to apprehend the kind of
confusion of ideas that could provoke such a question.
-- Charles Babbage
_______________________________________________
EUGLUG mailing list
[email protected]
http://www.euglug.org/mailman/listinfo/euglug