How to kill 3 processes with totally different names? [closed]

An example for killing gnome-disks and gnome-system-monitor.

kill $(pidof gnome-disks gnome-system-monitor)

I'm sure we have this around here already in some form, because someone here must have told me something like this years ago.

You could make it prettier, but more complicated like this:

# Provide a white space separated list of program names to be killed
programs_to_kill="gnome-disks gnome-system-monitor"
kill $(pidof $programs_to_kill)

If you really want to use grepping, you can use pkill to get the process-ids (pids). pkill greps for some pattern in the process names and kills the found processes.

The syntax you can use is:

pkill 'process_name1|other_process|something_else'

You can use pgrep (process grep) to check what you are about to kill with pkill.
The syntax is very similar:

pgrep -l 'proces_name1|other_process|something_else'

For example, if I run the following command on my machine, I get a listing of matches with their pids:

$ pgrep -l 'clamd|dockerd|snapd'
1952 snapd
1989 clamd
2085 dockerd
2813 dockerd

Warning: If you actually know the full process names, please use LiveWireBT's answer of:

kill $(pidof process_name1 other_proces)

That way, ssh-agent and sshd won't be the victim when you run pkill ssh and didn't pay attention to what pgrep -l ssh said.


killall name1 && killall name2 && killall name3