Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A process with name=example can be killed by

killall -9 example

How to kill multiple instances of following command which contain spaces?

"valgrind --tool=lackey ./testcases/kernel/syscalls/waitpid/waitpid03"

Following command returns valgrind --tool=lackey ./testcases/kernel/syscalls/waitpid/waitpid03: No such file or directory

killall -9 "valgrind --tool=lackey ./testcases/kernel/syscalls/waitpid/waitpid03"

share|improve this question
Escape the spaces with a \ (backslash)? – Daniel Beck Dec 10 '10 at 10:42
killall -9 "valgrind\ --tool=lackey\ ./testcases/kernel/syscalls/waitpid/waitpid03" – usajbalt Dec 10 '10 at 10:49
killall -9 valgrind\ --tool=lackey\ ./testcases/kernel/syscalls/waitpid/waitpid03...Both these command don't work. – usajbalt Dec 10 '10 at 10:49
-9 is a last resort. You should use -SIGTERM, -SIGINT or -SIGQUIT first to give the application a chance to do cleanup and exit gracefully. – Dennis Williamson Dec 10 '10 at 16:51
up vote 6 down vote accepted

killall valgrind will kill all valgrind processes regardless of arguments. If you want to kill only processes whose command line is exactly valgrind --tool=lackey ./testcases/kernel/syscalls/waitpid/waitpid03, you can use pkill:

pkill -xf 'valgrind --tool=lackey ./testcases/kernel/syscalls/waitpid/waitpid03'

Like killall, pkill is on every non-embedded (and some embedded) Linux installations, and it's more powerful and often more reliable (but for some reason less well-known). The companion utility pgrep is identical except that it lists the PIDs instead of killing.

Another utility you may be interested in is fuser: fuser testcases/kernel/syscalls/waitpid/waitpid03 lists the processes that have the specified file open, and fuser -k would send a signal to these processes. When you're not trying to send a signal, lsof is a more powerful alternative to fuser (shows more stuff, has more filters).

share|improve this answer
Your example didn't work for me but this did: pkill -f 'valgrind --tool=lackey ./testcases/kernel/syscalls/waitpid/waitpid03' – JohnMudd Jan 31 '13 at 22:58
@JohnMudd You're right, thanks. I'm pretty sure I intended to include these quotes, the command I posted makes no sense. Also -fx to “match the command line exactly”. – Gilles Jan 31 '13 at 23:06

You don't need to give killall the complete command line; killall valgrind would be sufficient in your case.

~$ perl -e 'sleep 10000' &
[1] 3586
~$ ps ax | grep perl
 3586 pts/3    S      0:00 perl -e sleep 10000
 3588 pts/3    S+     0:00 grep perl
~$ killall perl
[1]+  Terminated              perl -e 'sleep 10000'
share|improve this answer

As well as the other good solutions, you could always install htop and then kill what you want by scrolling through the list of running processes and using the F9 (kill) key. Ok, it's not hard-nosed, command line stuff but it works!

share|improve this answer

killall valgrind usually doesn't work since the actual valgrind executable has another name. This name is memcheck-amd64-linux or similar, depending amongst other things on which valgrind tool you are using. What ps reports as the process name is not the executable name though, but the first entry in the command line. This causes confusion. I've reported this to psmisc:

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .