{"id":2796,"date":"2018-01-26T17:43:45","date_gmt":"2018-01-26T14:43:45","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-kill-command\/"},"modified":"2018-01-26T17:43:45","modified_gmt":"2018-01-26T14:43:45","slug":"linux-kill-command-tutorial-for-beginners-5-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-kill-command-tutorial-for-beginners-5-examples\/","title":{"rendered":"Linux kill Command Tutorial for Beginners (5 Examples)"},"content":{"rendered":"<p>Sometimes, while working on a Linux machine, you&#8217;ll see that an application or a command line process gets stuck (becomes unresponsive). Then in those cases, terminating it is the only way out. Linux command line offers a utility that you can use in these scenarios. It&#8217;s called <strong>kill<\/strong>.<\/p>\n<p>In this tutorial, we will discuss the basics of kill using some easy to understand examples. But before we do that, it&#8217;s worth mentioning that all examples in the article have been tested on an Ubuntu 16.04 machine.<\/p>\n<h2 id=\"linux-kill-command\">Linux kill command<\/h2>\n<p>The kill command is usually used to kill a process. Internally it sends a signal, and depending on what you want to do, there are different signals that you can send using this tool. Following is the command&#8217;s syntax:<\/p>\n<p class=\"command\">kill [options] &lt;pid&gt; [&#8230;]\n<p>And here&#8217;s how the tool&#8217;s man page describes it:<\/p>\n<pre>The default signal for kill is TERM. Use -l or -L to list available signals. Particularly useful <br\/>signals include HUP, INT, KILL, STOP, CONT, and 0. Alternate signals may be specified in three ways:<br\/>-9, -SIGKILL or -KILL. Negative PID values may be used to choose whole process groups; see the PGID<br\/>column in ps command output.\u00a0 A PID of -1 is special; it indicates all processes except the kill<br\/>process\u00a0 itself and init.<\/pre>\n<p>The following Q&amp;A-styled examples should give you a better idea of how the kill command works.<\/p>\n<h2 id=\"q-how-to-terminate-a-process-using-kill-command\">Q1. How to terminate a process using kill command?<\/h2>\n<p>This is very easy &#8211; all you need to do is to get the pid of the process you want to kill, and then pass it to the kill command.<\/p>\n<p class=\"command\">kill [pid]\n<p>For example, I wanted to kill the &#8216;gthumb&#8217; process on my system. So i first used the ps command to fetch the application&#8217;s pid, and then passed it to the kill command to terminate it. Here&#8217;s the screenshot showing all this:<\/p>\n<p><a class=\"fancybox\" id=\"img-kill-default\" href=\"https:\/\/www.howtoforge.com\/images\/usage_of_pfsense_to_block_dos_attack_\/big\/kill-default.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/01\/linux-kill-command-tutorial-for-beginners-5-examples.png\" alt=\"How to terminate a process using kill command\" width=\"500\" height=\"79\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-send-a-custom-signal\">Q2. How to send a custom signal?<\/h2>\n<p>As already mentioned in the introduction section, TERM is the default signal that kill sends to the application\/process in question. However, if you want, you can send any other signal that kill supports using the <strong>-s<\/strong> command line option.<\/p>\n<p class=\"command\">kill -s [signal] [pid]\n<p>For example, if a process isn&#8217;t responding to the TERM signal (which allows the process to do final cleanup before quitting), you can go for the KILL signal (which doesn&#8217;t let process do any cleanup). Following is the command you need to run in that case.<\/p>\n<p class=\"command\">kill -s KILL [pid]\n<h2 id=\"q-what-all-signals-you-can-send-using-kill\">Q3. What all signals you can send using kill?<\/h2>\n<p>Of course, the next logical question that&#8217;ll come to your mind is how to know which all signals you can send using kill. Well, thankfully, there exists a command line option <strong>-l<\/strong> that lists all supported signals.<\/p>\n<p class=\"command\">kill -l<\/p>\n<p>Following is the output the above command produced on our system:<\/p>\n<p><a class=\"fancybox\" id=\"img-kill-l-option\" href=\"https:\/\/www.howtoforge.com\/images\/usage_of_pfsense_to_block_dos_attack_\/big\/kill-l-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/01\/linux-kill-command-tutorial-for-beginners-5-examples-1.png\" alt=\"What all signals you can send using kill\" width=\"500\" height=\"165\" title=\"\"><\/a><\/p>\n<h2 id=\"q-what-are-the-other-ways-in-which-signal-can-be-sent\">Q4. What are the other ways in which signal can be sent?<\/h2>\n<p>In one of the previous examples, we told you if you want to send the KILL signal, you can do it in the following way:<\/p>\n<p class=\"command\">kill -s KILL [pid]\n<p>However, there are a couple of other alternatives as well:<\/p>\n<p class=\"command\">kill -s SIGKILL [pid]\n<p class=\"command\">kill -s 9 [pid]\n<p>The corresponding number can be known using the -l option we&#8217;ve already discussed in the previous example.<\/p>\n<h2 id=\"q-how-to-kill-all-running-process-in-one-go\">Q5. How to kill all running process in one go?<\/h2>\n<p>In case a user wants to kill all processes that they can (this depends on their privilege level), then instead of specifying a large number of process IDs, they can simply pass the -1 option to kill.<\/p>\n<p>For example:<\/p>\n<p class=\"command\">kill -s KILL -1<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>The kill command is pretty\u00a0straightforward to understand and use. There&#8217;s a slight learning curve in terms of the list of signal options it offers, but as we explained in here, there&#8217;s an option to take a quick look at that list as well. Just practice whatever we&#8217;ve discussed and you should be good to go. For more information, head to the tool&#8217;s <a href=\"https:\/\/linux.die.net\/man\/1\/kill\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a>.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes, while working on a Linux machine, you&#8217;ll see that an application or a command line process gets stuck (becomes unresponsive). Then in those cases, terminating it is the only way out. Linux command line offers a utility that you can use in these scenarios. It&#8217;s called kill. In this tutorial, we will discuss the &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-2796","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=2796"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2796\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=2796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=2796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=2796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}