|> Consider the following shell script
|>
|> #!/bin/ksh
|> hndlr ()
|> {
|> echo caught signal
|> exit 1
|> }
|>
|> trap hndlr 1 2 3 15
|> sleep 100
|>
|> Suppose I run this script in the background and do "kill -15" on
|> the shell script pid (not the sleep pid), the shell script does not print
|> "caught signal" until the sleep timer expires. However if I send a SIGHUP (1),
|> the "caught signal" message is printed, but the sleep continues
|> to run till its timer expires. I have two questions:
|> 1. Why is this strange behavior?
|> 2. How can I cause sleep to terminate without waiting for timer?
|>
the bournish shells will not call a trap handler when they are in a
wait for a subprocess.
in the bash you can use a direct wait call to work around this behaviour.
I don't have the ksh to test this with it.
look at the following example:
#! /usr/local/bin/bash
sig_term()
{
echo "signal SIGTERM reached"
kill -TERM $CHILDPID 2>/dev/null
Quote:}
sig_hup()
{
echo "signal SIGHUP reached"
kill -HUP $CHILDPID 2>/dev/null
Quote:}
trap sig_term 15
trap sig_hup 1
exec sleep 100 &
CHILDPID=$!
wait $CHILDPID
# END-OF-SCRIPT
the sleep will be done asynchronly in a subshell and with an exec call to
substitute the subshell with sleep. then the child pid is saved for use
in signal handlers and an explicit wait call is done
the signals SIGHUP and SIGTERM will be catched and propagated to the
child process. then the wait call ends up because the child has
terminated.
kf
--