home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 38.16 Why You Can't Kill a Zombie Chapter 38
Starting, Stopping, and Killing Processes
Next: 38.18 nohup
 

38.17 Automatically Kill Background Processes on Logout in csh

In many versions of the Bourne shell, background processes (1.26 ) 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 (3.1 ) :

/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 (47.2 ) . [To watch this work, put set verbose echo (8.17 ) 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 (40.2 ) 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 (38.4 ) 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


Previous: 38.16 Why You Can't Kill a Zombie UNIX Power Tools Next: 38.18 nohup
38.16 Why You Can't Kill a Zombie Book Index 38.18 nohup

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System










??????????????@Mail.ru