gaynor@topaz.RUTGERS.EDU (Silver) (07/03/86)
Hi. I have some cshell source code that isn't performing quite
the way I intend. I have extracted the relevant code, below.
----------
#!/bin/csh
onintr clean_up
while (1)
work_like_a_horse
sleep 10
end
clean_up:
clean_up_horses_mess
----------
Now, when the process is in the foreground, and I interrupt it
it with ^C, it halts nicely, cleaning itself up. However, when
the process is in the background, and I send it a kill signal,
it just plain rolls over and dies. No clean up is performed
(leaving all kinds of junk in /tmp :-).
Have I misinterpreted this excerpt from 'man csh'?
onintr
onintr -
onintr label
Control the action of the shell on interrupts. The
first form restores the default action of the shell on
interrupts which is to terminate shell scripts or to
return to the terminal command input level. The second
form `onintr -' causes all interrupts to be ignored.
###########################################################
# The final form causes the shell to execute a `goto #
# label' when an interrupt is received or a child process #
# terminates because it was interrupted. #
###########################################################
In any case, if the shell is running detached and
interrupts are being ignored, all forms of onintr have
no meaning and interrupts continue to be ignored by the
shell and all invoked commands.
I got the impression that - well, you can tell that I always
intend to execute the clean up code ANY time the process is
gunned, despite the caliber. What does it take?
Thanks in advance...
Silver {...topaz!gaynor}avolio@decuac.DEC.COM (Frederick M. Avolio) (07/04/86)
In article <5273@topaz.RUTGERS.EDU>, gaynor@topaz.RUTGERS.EDU (Silver) writes: > Hi. I have some cshell source code that isn't performing quite > the way I intend. I have extracted the relevant code, below. > ... > Now, when the process is in the foreground, and I interrupt it > it with ^C, it halts nicely, cleaning itself up. However, when > the process is in the background, and I send it a kill signal, > it just plain rolls over and dies. No clean up is performed How do you kill it? Do you send it an SIGINT? (kill -2 pid) Or just a "kill pid" which sends a SIGTERM (signal 15)? It works if you send an interrupt (kill -2 pid). Use the Bourne shell for programming.... more control over such things (it allows you to specify the signals to catch). -- Fred @ DEC Ultrix Applications Center INET: avolio@decuac.DEC.COM * Fight the Fight * UUCP: {decvax,seismo,cbosgd}!decuac!avolio * Rescue the Unborn *