Automatically Kill Background Processes on Logout in csh
In many versions of the Bourne shell, background processes () are automatically killed with a HANGUP signal (signal 1) on logout. But the C shell makes background processes immune to signals and a HANGUP signal at logout doesn't affect the processes; they keep running.
If you want the C shell to work like the Bourne shell, put lines like these in your logout file ():
/tmp ! -z -v eval |
set tf=/tmp/k$$ jobs >$tf if (! -z $tf) then # there are jobs jobs >$tf.1 # rerun it to dump `Done' jobs # skip Stopped jobs (killed by default) grep -v Stopped <$tf.1 >$tf; rm $tf.1 # cannot use a pipe here if (! -z $tf) then # there are running jobs eval `echo kill -1; sed 's/.\([0-9]*\).*/%\1/' <$tf` endif endif rm $tf |
---|
Warning: this may run afoul of various csh quirks (). [To watch this work, put set
verbose
echo
() at the top of your logout file. If the logout process clears your screen or closes the window, you can give yourself n
seconds to read the debugging output by adding sleep
n
() to the end of your logout file. -JP ] The important trick is to run jobs >file
, not jobs | command
, as the latter runs jobs in a subshell () and thus produces no output, although jobs
|
any-csh-builtin
is good for a laugh :-)
.
- CT in comp.unix.questions on Usenet, 5 August 1989