How To Kill Multiple Processes

cron gone mad? Lots of backup processes on your server?

There are a number of way to kill multiple processes on a Linux server when normal daemon shutdown procedures don’t work. The easiest is probably to use killall(1), but do not use this command on an HP-UX system.

An example:

killall apache2

That command will send a signal (SIGTERM) to all processes running apache2 (note that there are better ways of simply stopping Apache under normal circumstances).

If that fails – and only if you understand the significance of doing this – you can kill the processes with:

killall -9 apache2

That will send a KILL signall to all processes running apache2.

Another technique is to use the output of the ps command to generate a list of processes to kill. For example:

ps h -o pid= -u freddy | xargs kill

That command will send a SIGTERM signal to every process run by user freddy. If -9 is appended to the above line, a KILL signal will be sent instead.

How it works

The ps command lists processes running on the system.

The -o pid= switch specifies that only the process ID (pid) should be output. The equals sign redefines the header for the column, in this case to nothing, so no header is output.

The -u freddy restricts the listing to processes with an effective user ID of freddy

The xargs kill command will send a kill command to each PID passed to it.

Back to Linux Tips and Advice

© 2012 Tiger Computing Ltd, Wyastone Business Park, Wyastone Leys, Monmouth, NP25 3SR | Legal | Sitemap