How to kill a process in Linux

This guide will go through how to kill a process in Linux. Linux comes with a built-in command called kill that is used to manually end processes.

How to kill a process in Linux

We will go through common kill commands such as kill, pkill, killall, xkill, etc. The command doesn’t end the process on its own. Instead, they direct a specific signal to the desired process or processes. SIGTERM(15) is the default signal when not specified.

Kill Command

  • List the signals used to kill the process. The most used signal is 1, 9 and 15.
kill -l

Sample output

1) SIGHUP     2) SIGINT   3) SIGQUIT  4) SIGILL   5) SIGTRAP
 6) SIGABRT     7) SIGBUS   8) SIGFPE   9) SIGKILL 10) SIGUSR1
11) SIGSEGV    12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT    17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN    22) SIGTTOU 23) SIGURG  24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM    27) SIGPROF 28) SIGWINCH    29) SIGIO   30) SIGPWR
31) SIGSYS    34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4    39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9    44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14    49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11    54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6    59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1    64) SIGRTMAX
  • List all running processes with their PID using the command below.
ps -A

Sample output

763 ?        00:00:00 cron
    764 ?        00:00:02 dbus-daemon
    765 ?        00:00:00 NetworkManager
    771 ?        00:00:00 irqbalance
    773 ?        00:00:00 networkd-dispat
    774 ?        00:00:02 polkitd
    775 ?        00:00:00 power-profiles-
    776 ?        00:00:00 rsyslogd
    778 ?        00:00:00 switcheroo-cont
    779 ?        00:00:00 systemd-logind
    780 ?        00:00:00 udisksd
    781 ?        00:00:00 wpa_supplicant
    813 ?        00:00:00 avahi-daemon
    861 ?        00:00:00 cupsd
    863 ?        00:00:08 redis-server
    866 ?        00:00:00 unattended-upgr
    871 ?        00:00:00 ModemManager
    883 ?        00:00:00 gdm3
   1002 ?        00:00:00 kerneloops
   1004 ?        00:00:00 kerneloops
   1006 ?        00:00:00 cups-browsed
   1096 ?        00:00:00 rtkit-daemon
   1311 ?        00:00:00 upowerd
   1348 ?        00:00:00 packagekitd
   1532 ?        00:00:00 colord
   1565 ?        00:00:00 gdm-session-wor
   1572 ?        00:00:01 systemd
   1573 ?        00:00:00 (sd-pam)
   1580 ?        00:00:00 pipewire
   1581 ?        00:00:00 pipewire-media-
   1582 ?        00:00:00 pulseaudio
   1583 ?        00:00:01 snapd-desktop-i
   1586 ?        00:00:00 dbus-daemon
   1595 ?        00:00:00 gvfsd
   1596 ?        00:00:00 gnome-keyring-d
   1607 ?        00:00:00 gvfsd-fuse
   1608 ?        00:00:00 xdg-document-po
   1618 ?        00:00:00 xdg-permission-
   1625 ?        00:00:00 fusermount3
   1638 tty2     00:00:00 gdm-wayland-ses
   1641 ?        00:00:01 tracker-miner-f
   1642 tty2     00:00:00 gnome-session-b
   1712 ?        00:00:00 gnome-session-c
   1723 ?        00:00:00 gnome-session-b
   1742 ?        00:00:00 at-spi-bus-laun
   1744 ?        00:00:45 gnome-shell
   1753 ?        00:00:00 dbus-daemon
   1788 ?        00:00:00 gvfs-udisks2-vo
   1795 ?        00:00:00 gvfs-goa-volume
   1799 ?        00:00:00 goa-daemon
   1806 ?        00:00:00 goa-identity-se
   1811 ?        00:00:00 gvfs-afc-volume
   1817 ?        00:00:00 gvfs-gphoto2-vo
   1821 ?        00:00:00 gvfs-mtp-volume
   1827 ?        00:00:00 gnome-shell-cal
   1834 ?        00:00:00 evolution-sourc
   1843 ?        00:00:00 xdg-desktop-por
   1847 ?        00:00:00 evolution-calen
   1851 ?        00:00:00 xdg-desktop-por
   1857 ?        00:00:00 gvfsd-trash
   1865 ?        00:00:00 gjs
   1867 ?        00:00:00 at-spi2-registr
   1877 ?        00:00:00 sh
   1878 ?        00:00:00 gsd-a11y-settin
   1881 ?        00:00:00 ibus-daemon
   1882 ?        00:00:00 gsd-color
   1884 ?        00:00:00 gsd-datetime
   1885 ?        00:00:00 gsd-housekeepin
   1890 ?        00:00:00 gsd-keyboard
   1896 ?        00:00:00 gsd-media-keys
   1900 ?        00:00:00 gsd-power
   1903 ?        00:00:00 gsd-print-notif
   1911 ?        00:00:00 gsd-rfkill
   1918 ?        00:00:00 gsd-screensaver
   1926 ?        00:00:00 gsd-sharing
   1932 ?        00:00:00 gsd-smartcard
   1938 ?        00:00:00 evolution-alarm
   1942 ?        00:00:00 gsd-sound
   1943 ?        00:00:00 gsd-wacom
   1965 ?        00:00:00 ibus-memconf
   1968 ?        00:00:02 ibus-extension-
   1978 ?        00:00:00 ibus-portal
   1986 ?        00:00:00 gsd-disk-utilit
   1987 ?        00:00:00 dconf-service
   1992 ?        00:00:05 vmtoolsd
   1995 ?        00:00:00 evolution-addre
   2022 ?        00:00:00 gsd-printer
   2068 ?        00:00:00 gvfsd-metadata
   2090 ?        00:00:00 ibus-engine-sim
   2093 ?        00:00:25 Xwayland
   2107 ?        00:00:00 xdg-desktop-por
   2109 ?        00:00:00 gjs
   2146 ?        00:00:01 gjs
   2157 ?        00:00:00 gsd-xsettings
   2203 ?        00:00:00 ibus-x11
   2217 ?        00:02:22 firefox
   2330 ?        00:00:03 gnome-terminal-
   2367 pts/0    00:00:00 bash
   2391 ?        00:00:00 Socket Process
   2423 ?        00:00:01 Privileged Cont
   2453 ?        00:00:00 snap
   3486 ?        00:00:01 WebExtensions
   3658 ?        00:01:21 Isolated Web Co
   4001 ?        00:00:00 update-notifier
   5251 ?        00:00:03 snapd
   5937 ?        00:00:03 kworker/1:0-events
   5989 ?        00:00:02 kworker/0:2-events
   6251 ?        00:00:00 kworker/u256:2-ext4-rsv-conversion
   6278 ?        00:00:00 kworker/1:1-events
   6352 ?        00:00:00 kworker/u256:3-events_unbound
   6367 ?        00:00:00 kworker/u256:0-flush-8:0
   6377 ?        00:00:00 kworker/0:1-events
   6436 ?        00:00:00 kworker/0:0-rcu_par_gp
   6448 ?        00:00:00 Isolated Servic
   6464 ?        00:00:00 kworker/1:2-events
   6474 ?        00:00:00 Web Content
   6500 ?        00:00:00 Web Content
   6577 ?        00:00:00 kworker/u256:1-events_unbound
   6875 ?        00:00:00 Web Content
   7051 ?        00:00:00 apache2
   7052 ?        00:00:00 apache2
   7053 ?        00:00:00 apache2
   7169 ?        00:00:00 htcacheclean
   7196 ?        00:00:00 kworker/1:3-events
   7318 pts/0    00:00:00 ps
  • To kill a specific process e.g. Redis-server in the processes above output. We will use the format kill <signal_or_options> <PID(s)>
sudo kill -9 863

Pkill Command

  • You can also kill a process by its name part e.g.
sudo pkill redis
  • To kill a process by a specific name add the -x option as shown below.
sudo pkill -x redis-server

Killall Command

  • Killall command is another command that can be used to kill a process by its name though it uses a specific name only. Killall command will kill all processes that run on a specific process name e.g. let’s say Apache has 3 processes 7051, 7052 & 7053 by running the command below will terminate the three processes.
sudo killall -9 apache2 
  • Killall command can also be used to kill a process older than a specific time using the -o option e.g. to kill a process older than 1 day, use the command below. Note, you can replace d with s(for seconds), m(for minutes), d(for days), w(for weeks), M(for months) and y(for years).
sudo killall -o 1d nginx
  • To kill process younger than a specific time using the -y option e.g.
sudo killall -y 1d nginx
  • You can also kill specific user processes in your system. e.g. user1
sudo killall apache2 -u user1

Xkill command

  • Xkill command is used to kill an open program. After running xkill command on the terminal left click on the program window to kill it. Xkill command comes in handy when you have programs that aren’t responding.
xkill

Sample output

Select the window whose client you wish to kill with button 1....
xkill:  killing creator of resource 0x160003c
  • You have reached the end of our article, we have gone through how to kill a process in Linux using the most used commands.

Read more about kill commands on the man pages

Other Tutorials

Setup Nagios Passive Checks with NRDP

Install PostgreSQL on FreeBSD 13

Install Redis on FreeBSD 13

System administrator | Software Developer | DevOps

Leave a Comment