{"id":23588,"date":"2019-08-07T21:30:46","date_gmt":"2019-08-07T18:30:46","guid":{"rendered":"https:\/\/computingforgeeks.com\/?p=23588"},"modified":"2026-03-20T01:00:42","modified_gmt":"2026-03-19T22:00:42","slug":"how-to-kill-a-process-in-linux-with-examples","status":"publish","type":"post","link":"https:\/\/computingforgeeks.com\/how-to-kill-a-process-in-linux-with-examples\/","title":{"rendered":"How To kill a process in Linux with examples"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>Moments come when a process in your Linux system begins to behave weirdly and you as an Administrator needs to stop it for the good of the health of the whole system. The following utilities will help you find the process and stop it.<\/p>\n\n\n\n<p>Before we proceed, as we know, every Linux process has a process identification (PID) and we will have to look for the particular PID of interest. For this, we can use the following tools<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using ps command<\/h2>\n\n\n\n<p>This command reports a snapshot of the current processes.<\/p>\n\n\n\n<p>To list all processes, just run <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps -A<\/code><\/pre>\n\n\n\n<p>To filter your output, you can use pipes to get to the exact process you need, for example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps aux | grep apa<\/code><\/pre>\n\n\n\n<p>This will list all processes that have the above letters in their process names. From there, you can narrow down and get the exact PID of your culprit.<\/p>\n\n\n\n<p>As a substitute in your armory of commands, you can also use pidof or <em>pgrep<\/em> as follows<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pidof zsh<\/code><\/pre>\n\n\n\n<p>That will return the PID of zsh process<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pgrep zsh<\/code><\/pre>\n\n\n\n<p>That will also return the PID of the <em>zsh<\/em> process.<\/p>\n\n\n\n<p>After you discover the PID, the next step is to stop the process. There are various tools here for example: <strong>kill<\/strong>, <strong>killall<\/strong>, <strong>pkill, top, <\/strong>and others.<\/p>\n\n\n\n<p>You have to realize that these commands work as long as you have the right permissions to stop the processes themselves. If you do not have sufficient rights to kill other users&#8217; processes, they won&#8217;t work. You will be able to kill your own processes though.<\/p>\n\n\n\n<p>The root user as it can be guessed is the superuser and can kill any process belonging to any other user in the system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Kill process on Linux using kill command<\/h2>\n\n\n\n<p>kill sends a signal to a process. The signals can either be:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>SIGHUP<\/strong> which can be represented with 1 and causes the process to Hangup<\/li><li><strong>SIGKILL<\/strong>    which can be represented with 9 and causes the process to be Killed ungracefully<\/li><li><strong>SIGTERM<\/strong> which can be represented with 15 and causes the process to be Killed gracefully<\/li><\/ul>\n\n\n\n<p>If the <em>kill<\/em> command is executed without options, SIGTERM is used by default.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Examples of kill in action<\/h4>\n\n\n\n<p>Kills process with PID 7089 without saving any open files<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">kill -9 7089 <\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">kill -SIGKILL 7089<\/mark><\/code><\/pre>\n\n\n\n<p>Kills process with PID 7080 after it has made sure all of its files are saved. This is gracefully killing of the process:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\">kill -15 7080<\/mark>\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">kill -SIGTERM 7080<\/mark><\/code><\/pre>\n\n\n\n<p>Another command that you can take advantage of is the killall command. If you know the name of the process, there is no need of finding its PID. killall kills it by name as shown below.<\/p>\n\n\n\n<p>For more options, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>man kill<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Kill process on Linux using killall command<\/h2>\n\n\n\n<p>The <strong>killall<\/strong> command kills processes by their name as prescribed above. Just do:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>killall httpd<\/code><\/pre>\n\n\n\n<p>To learn more, check man page:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>man killall<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Kill process on Linux using pkill command<\/h2>\n\n\n\n<p>Signals processes based on name and other attributes<\/p>\n\n\n\n<p>pkill works in a similar way as killall. Its syntax is as simple as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pkill &#91;options] pattern<\/code><\/pre>\n\n\n\n<p>pkill sends signals to processes based on name and other attributes.<\/p>\n\n\n\n<p>Using pkill is very simple if you know the name of the process to pass the command and the name of the process as shown below. It uses SIGTERM signal by default but it can be changed if you like.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pkill nginx<\/code><\/pre>\n\n\n\n<p>All command options:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-pale-pink-color\"> pkill --help<\/mark>\nUsage:\n pkill &#91;options] &lt;pattern>\n\nOptions:\n -&lt;sig>, --signal &lt;sig>    signal to send (either number or name)\n -e, --echo                display what is killed\n -c, --count               count of matching processes\n -f, --full                use full process name to match\n -g, --pgroup &lt;PGID,...>   match listed process group IDs\n -G, --group &lt;GID,...>     match real group IDs\n -i, --ignore-case         match case insensitively\n -n, --newest              select most recently started\n -o, --oldest              select least recently started\n -P, --parent &lt;PPID,...>   match only child processes of the given parent\n -s, --session &lt;SID,...>   match session IDs\n -t, --terminal &lt;tty,...>  match by controlling terminal\n -u, --euid &lt;ID,...>       match by effective IDs\n -U, --uid &lt;ID,...>        match by real IDs\n -x, --exact               match exactly with the command name\n -F, --pidfile &lt;file>      read PIDs from file\n -L, --logpidfile          fail if PID file is not locked\n --ns &lt;PID>                match the processes that belong to the same\n                           namespace as &lt;pid>\n --nslist &lt;ns,...>         list which namespaces will be considered for\n                           the --ns option.\n                           Available namespaces: ipc, mnt, net, pid, user, uts\n -h, --help     display this help and exit\n -V, --version  output version information and exit<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Kill process on Linux using top command<\/h2>\n\n\n\n<p>You can use the top command to kill a process through its interactive session while it is running. <\/p>\n\n\n\n<p>To kill processes directly from the &#8220;<strong>top<\/strong>&#8221; interface,  press &#8220;<strong>k<\/strong>&#8220;. It will ask you for the PID of the process to kill. <strong>Enter the PID<\/strong> and press enter. It uses <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>top - 10:07:55 up 1 day, 22:09,  0 users,  load average: 0.52, 0.58, 0.59\nTasks:   4 total,   1 running,   3 sleeping,   0 stopped,   0 zombie\n%Cpu(s):  4.7 us,  3.5 sy,  0.0 ni, 91.0 id,  0.0 wa,  0.7 hi,  0.0 si,  0.0 st\nKiB Mem : 16669896 total,  2348244 free, 14092300 used,   229352 buff\/cache\nKiB Swap: 50331648 total, 49101952 free,  1229696 used.  2443864 avail Mem\n<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">PID to signal\/kill &#91;default pid = 1] 10000<\/mark><\/code><\/pre>\n\n\n\n<p>It uses SIGTERM signal by default as shown below. Just press enter again and top will do the rest.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>top - 10:07:55 up 1 day, 22:09,  0 users,  load average: 0.52, 0.58, 0.59\nTasks:   4 total,   1 running,   3 sleeping,   0 stopped,   0 zombie\n%Cpu(s):  4.7 us,  3.5 sy,  0.0 ni, 91.0 id,  0.0 wa,  0.7 hi,  0.0 si,  0.0 st\nKiB Mem : 16669896 total,  2348244 free, 14092300 used,   229352 buff\/cache\nKiB Swap: 50331648 total, 49101952 free,  1229696 used.  2443864 avail Mem\nSend pid 10000 signal &#91;15\/sigterm]<\/code><\/pre>\n\n\n\n<p>To learn more, check man page:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>man top<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>You now know how to kill that bogus or annoying Linux process using simple Linux tools that usually come pre-installed in almost all distributions. Thank you for reading through. If you are interested, you can peruse the guides below with similar topics.<\/p>\n\n\n\n<p><a href=\"https:\/\/computingforgeeks.com\/how-to-use-scp-command-to-securely-transfer-files-with-examples\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to use scp command to securely transfer files with examples<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/computingforgeeks.com\/top-10-free-backup-software-for-linux\/\" target=\"_blank\">Top 10 Free Backup software for Linux<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/computingforgeeks.com\/netstat-vs-ss-usage-guide-linux\/\" target=\"_blank\">netstat vs ss usage guide on Linux<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/computingforgeeks.com\/rsync-command-linux-examples\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">How to use rsync command on Linux\/Unix with examples<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/computingforgeeks.com\/how-to-check-tcp-connections-states-in-linux-with-netstat\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">How to Check TCP connections States in Linux with Netstat<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\"How to extract .xz files on Linux - CenOS \/ Ubuntu \/ Debian (opens in a new tab)\" href=\"https:\/\/computingforgeeks.com\/how-to-extract-xz-files-on-linux\/\" target=\"_blank\">How to extract .xz files on Linux &#8211; CenOS \/ Ubuntu \/ Debian<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/computingforgeeks.com\/customize-qcow2-raw-image-templates-with-virt-customize\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">How To Customize Qcow2\/Raw Linux OS disk image with virt-customize<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Moments come when a process in your Linux system begins to behave weirdly and you as an Administrator needs to stop it for the good of the health of the whole system. The following utilities will help you find the process and stop it. Before we proceed, as we know, every Linux process has &#8230; <a title=\"How To kill a process in Linux with examples\" class=\"read-more\" href=\"https:\/\/computingforgeeks.com\/how-to-kill-a-process-in-linux-with-examples\/\" aria-label=\"Read more about How To kill a process in Linux with examples\">Read more<\/a><\/p>\n","protected":false},"author":7,"featured_media":24376,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[299,12,17,330,26,50,9275,81],"tags":[12263,363,364],"class_list":["post-23588","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to","category-arch-linux","category-centos","category-cheat-sheets","category-debian","category-linux-tutorials","category-terminal","category-ubuntu","tag-cheats","tag-kill","tag-pkill"],"_links":{"self":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/23588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/comments?post=23588"}],"version-history":[{"count":1,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/23588\/revisions"}],"predecessor-version":[{"id":162912,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/23588\/revisions\/162912"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media\/24376"}],"wp:attachment":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media?parent=23588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/categories?post=23588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/tags?post=23588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}