Userspace programs for process management on Linux

kill

Despite its name (that it’s gotten from its most popular usecase), kill is very versatile tool used to send specified signals to individual processes, or process groups.

It is part of the util-linux collection of programs and is widely available.

Here area a couple of usage examples. If no signal name/number is specified, SIGTERM (15) is assumed:

  • kill firefox:

Send a SIGTERM (15) signal to every process invoked as 'firefox'.

  • kill 15222 152101 -8:

Send signal number 8 to PIDs 15222 and 152101.

  • kill 152101 firefox -SIGKILL

Send a SIGKILL (9) signal to PID 152101 and every process invoked as firefox.

  • kill -s 19 1022 kitty

Send signal number 19 to PID 1022 and every process invoked as kitty.

  • kill -SIGKILL -933

Send a SIGKILL (9) signal to all processes in the process group 933.

  • kill -p firefox

Don’t send any signals, but print PIDs of named processes listed, and exit.

pidof

pidof is a tool used to list PIDs of processes by name. It doesn’t conduct any manipulation. It’s very useful when dealing with other , more primitive tools that conduct process manipulation but don’t have the ability to find PIDs based on their names.

Here are some usage examples:

  • pidof firefox

List PIDs of all processes with the name 'firefox'. PIDs are by default separated by space.

  • pidof firefox kitty -S x

List PIDs of all processes with the names 'firefox' or 'kitty', and separate PIDs with the character 'x'.

killall

killall is kill on steroids. In addition to support the same operations as kill, it sports a bunch of other features, such as case insensitive search, matching process names using regexes, killing all processes belonging to a group of a specified process, filtering processes based on spawn-time and owning user…

Here are some usage examples that demonstrate functionality not available in kill:

  • killall firefox -Ii --user bogdan --younger-than 4.2m

Case-insensitively match every process’ name agaisnt firefox that belongs to the user bogdan, was spawned less than 4.2 minutes ago, and send a SIGTERM (15) to it. Interactively ask the user to confirm each match.

  • killall -I -9 -r 'kitty[1-9]+\.19'

Case-insenstively match every process against the specified regex, and send it a SIGKILL (9) signal, prompting the user before every match.

pgrep, pkill

These two are pretty similar killall, though they have even more functionality. pgrep matches process names against regexes and prints them out, while pkill does the same in addition to sending signals.

They sport options such as -c (suppresses normal output and prints a count of process matches to stdout, eliminating the need for hacky shell piping such - this can be interpreted as a good or a bad thing). Another example is the ability to test for multiple owning users (e.g. -u bogdan,root) will match processes owned by either the bogdan, or root users.

These two are the ones that I use most often, probably after kill.


In addition to the tools described here, other, more sophisticated alternatives have their ways of manipulating processes as well. Tools such as top or htop for example allow you to browse and manipulate processes in real time.