The kill command can terminate the process by the process ID or name, and the killall command can terminate the process itself and its associated processes by the process name.

Options

kill Command Options

Here are some options for kill command:

Option Description
-s or ‑‑signal signal The number or name of the signal to be sent.
-l or ‑‑list [number] Output the number and name of available signals.
-p or ‑‑pid Show the process ID of the specified processes instead of sending any signals.
‑‑verbose Show the specified process IDs which signaled by the kill command along with the sent signal itself.

killall Command Options

Here are some options for killall command:

Option Description
-e or ‑‑exact Match the full name of the program instead of the short name, and the content after 15 characters will be truncated.
-I or ‑‑ignore-case case insensitive.
-g or ‑‑process-group Terminates the group to which the process belongs.
-i or ‑‑interactive Ask the user to confirm when the termination operation is performed.
l or ‑‑list Lists all available signal names.
-q or ‑‑quiet Do not show message if no processes were terminated.
-r or ‑‑regexp Use regular expressions to match.
-s or ‑‑signal or -SIGNAL Send the specified signal instead of SIGTERM.
-u or ‑‑user Terminates processes belonging to the specified user.
-v or ‑‑verbose If the signal is sent successfully, a success message is displayed.
-y or ‑‑younger-than Match young processes that start after a certain time. Available units are: s=seconds,m=minutes,h=hours,d=days,w=weeks,M=Months,y=years
-Z or ‑‑context Processes that have security contexts that match the extended regular expression pattern.

Examples

kill Command Examples

Output Available Signal IDs and Names

1
kill -l
img

Kill Background Running Processes

1
2
3
4
vi &
jobs
kill -s 9 4403
jobs
img

killall Command Examples

Output Available Signal Names

1
killall -l
img

We install nginx for this demonstration:

1
2
yum install nginx -y
nginx    # Start nginx server

Output nginx running processes:

1
ps aux | grep nginx
img

Terminating all processes:

1
2
killall nginx
ps aux | grep nginx
img

References KILL(1), KILLALL(1)

Buy me a coffeeBuy me a coffee