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


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 38.11 Printer Queue Watcher: A Restartable Daemon Shell Script Chapter 38
Starting, Stopping, and Killing Processes
Next: 38.13 Interactively Kill Processes Matching a Pattern
 

38.12 Killing All Your Processes

On many UNIX systems, kill ( 38.10 ) interprets the special "process ID" -1 as a command to signal all your processes (all processes with your user ID), except for the process sending the signal. So, for example, the command:

% 

kill -TERM -1

will terminate all your processes. [5] To see if your system supports this feature, type man 2 kill ( 50.1 ) to read the kill (2) manual page.

[5] Signal 15 is SIGTERM , which is the signal kill sends by default. In this command, you need to specify it explicitly, for obvious syntactic reasons.

You can use this to prevent background jobs from continuing after you logout; just stick kill -TERM -1 into your .logout file. There are some good reasons not to do this though: if you use several terminals, this will kill all your processes when you log out from any terminal.

This command is also useful in desperate situations. If processes are spawning out of control, or if your terminal is locked, you can log in from another terminal and kill everything, without having to dig through ps ( 38.5 ) to find the right process. [The zap ( 38.13 ) script searches process lists and kills processes automatically. - JP  ]

The special -1 process ID is defined differently for the superuser; if you're root, it means "all processes except system processes."

If you can't use the -1 process ID, and you use the Bourne shell or another shell without job control, you can use a 0 (zero) process ID. That sends the signal to all members of the process group (that is, processes resulting from the current login). A 0 doesn't work on shells, like the C shell, that have job control ( 12.1 ) .

- ML , JP , JIK


Previous: 38.11 Printer Queue Watcher: A Restartable Daemon Shell Script UNIX Power Tools Next: 38.13 Interactively Kill Processes Matching a Pattern
38.11 Printer Queue Watcher: A Restartable Daemon Shell Script Book Index 38.13 Interactively Kill Processes Matching a Pattern

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