shell script does not pass on SIGTERM to child process

shell script does not pass on SIGTERM to child process

Post by Srinivas Thons » Wed, 31 May 1995 04:00:00



Consider the following shell script

#!/bin/ksh
hndlr ()
{
    echo caught signal
    exit 1

Quote:}

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?

 
 
 

shell script does not pass on SIGTERM to child process

Post by Ananda M. K » Wed, 31 May 1995 04:00:00



-> 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?

   Apparently ksh does not process signals except at certain times.  This,
   I suppose, is necessary to some extent.  In particular, I would expect
   the shell to NOT process signals during the execution of any one line
   of the script....but only between lines.

-> 2. How can I cause sleep to terminate without waiting for timer?

   Divide the sleep 100 into 10 lines of "sleep 10".

   Ananda

--
Ananda M. Kar |(H)458-9754 | URL: http://www.cs.utexas.edu/users/ananda/
------------------------------------------------------------------------
  I am Pentium of Borg , Division is futile , You will be Approximated

 
 
 

shell script does not pass on SIGTERM to child process

Post by Kurt Fran » Thu, 01 Jun 1995 04:00:00


|> 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

--

 
 
 

shell script does not pass on SIGTERM to child process

Post by Srinivas Thons » Thu, 01 Jun 1995 04:00:00


Your solution worked in ksh. Thanks a lot for your time.
 
 
 

1. SEGV not killing child process of shell script

I have a shell script (ksh) that sources some stuff then starts a
process.

The process is run in the foreground so it waits for the process to
complete. The problem I'm having is that if you send a kill -10 (BUS)
signal to the shell script process - the script and child both die
correctly.

However - If I send a kill -11 (SEGV) signal to the script pid then
the script dies but the child is left running.

Anyone know what the reason is for this?

Thanks,

Darrell

2. Thanx! And read my requittal.

3. killing a shell script is not killing child processes

4. ghost script fonts

5. .BASHRC NOT RUNNING

6. How to pass a variable from a shell script to another shell script...

7. Two IP Adress

8. Shell script to start another one without being child process

9. How to wait for children of processes invoked in my shell script

10. Bourne Shell script, that kills its child-processes?

11. child/sub process control with shell script?

12. smail failed to reap child process: No child processes