On many Unix systems, kill (Section 24.12) 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. For example, the following command will terminate all your processes:[74]
[74]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.
% kill -TERM -1
To see if your system supports this feature, type man 2 kill (Section 2.1) to read the kill(2) manual page.
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 (Section 24.5) to find the right process. The zap (Section 24.16) script searches process lists and kills processes automatically.
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, such as the C shell, that have job control (Section 23.3).
--ML, JP, and JIK
Copyright © 2003 O'Reilly & Associates. All rights reserved.