{"id":2844,"date":"2018-02-06T17:13:28","date_gmt":"2018-02-06T14:13:28","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-killall-command\/"},"modified":"2018-02-06T17:13:28","modified_gmt":"2018-02-06T14:13:28","slug":"linux-killall-command-for-beginners-8-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-killall-command-for-beginners-8-examples\/","title":{"rendered":"Linux killall Command for Beginners (8 Examples)"},"content":{"rendered":"<p>We&#8217;ve already discussed the\u00a0<a href=\"https:\/\/www.howtoforge.com\/linux-kill-command\/\" target=\"_blank\" rel=\"noopener\">kill command<\/a> that you can use in case you want to terminate processes in Linux. However, there exists another command line utility that you can use for the same purpose: <strong>killall<\/strong>. In this tutorial, we will discuss the basics of this command using some easy to understand examples.<\/p>\n<p>But before we do that, it&#8217;s worth mentioning that all examples included in this tutorial have been tested on Ubuntu 16.04 LTS.<\/p>\n<h2 id=\"linux-killall-command\">Linux killall command<\/h2>\n<p>The killall command lets you kill processes by name. Following is the tool&#8217;s syntax:<\/p>\n<p class=\"command\">killall [OPTIONS] name<\/p>\n<p>And here&#8217;s how the man page explains the tool:<\/p>\n<p class=\"system\">killall sends a signal to all processes running any of the specified commands. If no signal name is specified, SIGTERM is sent. Signals can be specified either by name (e.g.\u00a0 -HUP or -SIGHUP) or by number (e.g.\u00a0 -1) or by option -s.<\/p>\n<p>If\u00a0 the command name is not regular expression (option -r) and contains a slash (\/), processes executing that particular file will be\u00a0 selected for killing, independent of their name.<\/p>\n<p>killall returns a zero return code if at least one process has been killed for each listed command, or no commands were listed and at least one process matched the -u and -Z search criteria. killall\u00a0returns non-zero otherwise.<\/p>\n<p>A killall process never kills itself (but may kill other\u00a0 <g class=\"gr_ gr_168 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace\" id=\"168\" data-gr-id=\"168\">killall\u00a0 processes<\/g>).<\/p>\n<p>The following Q&amp;A-styled examples should give you a better idea on how the killall command works.<\/p>\n<h2 id=\"q-how-to-use-killall-command\">Q1. How to use killall command?<\/h2>\n<p>The tool&#8217;s basic usage is very easy &#8211; all you have to do is to pass the name of the process as argument to killall. For example, to kill the <em>gthumb<\/em> process that was running on my system, I used killall in the following way:<\/p>\n<p class=\"command\">killall gthumb<\/p>\n<p>Note that in case you aren&#8217;t aware of the exact name of the process, you can use the <em>ps<\/em> command to fetch this information.<\/p>\n<h2 id=\"q-is-killall-casesensitive\">Q2. Is killall case-sensitive?<\/h2>\n<p>Yes, it is. It throws an error &#8216;no process found&#8217; error if the user fails to write the process name in correct case. Following is an example:<\/p>\n<p><a class=\"fancybox\" id=\"img-killall-wrong-case\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/killall-wrong-case.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/linux-killall-command-for-beginners-8-examples.png\" alt=\"Is killall case-sensitive\" width=\"280\" height=\"55\" title=\"\"><\/a><\/p>\n<p>However, if you want, you can force killall to ignore case using the <strong>-I<\/strong> command line option.<\/p>\n<p><a class=\"fancybox\" id=\"img-killall-I-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/killall-I-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/linux-killall-command-for-beginners-8-examples-1.png\" alt=\"Killall ignore case\" width=\"309\" height=\"38\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-make-killall-ask-before-terminating-process\">Q3. How to make killall ask before terminating process?<\/h2>\n<p>Suppose you want the killall command to ask for user permissions before it kills a process, then you can use the <strong>-i<\/strong> command line option. This will make the killall operation interactive.<\/p>\n<p>For example:<\/p>\n<p><a class=\"fancybox\" id=\"img-killall-i-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/killall-i-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/linux-killall-command-for-beginners-8-examples-2.png\" alt=\"How to make killall ask before terminating process\" width=\"314\" height=\"37\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-choose-the-signal-killall-sends-to-process\">Q4. How to choose the signal killall sends to process?<\/h2>\n<p>By default, it&#8217;s the SIGTERM signal that killall sends to processes. However, you can send other signals as well. You can use the options\u00a0<strong>-s<\/strong>, <strong>&#8211;signal<\/strong>, and <strong>-SIGNAL<\/strong> to send these other signals.<\/p>\n<p>However, for this to work, you need to know what all signals the killall command can send. This you can do using the <strong>-l<\/strong> command line option.<\/p>\n<p class=\"command\">killall -l<\/p>\n<p>Following is the list the aforementioned command produced on our system:<\/p>\n<p><a class=\"fancybox\" id=\"img-killall-l\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/killall-l.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/linux-killall-command-for-beginners-8-examples-3.png\" alt=\"How to choose the signal killall sends to process\" width=\"500\" height=\"48\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-prevent-killall-from-complaining-if-specified-process-doesnt-exist\">Q5. How to prevent killall from complaining if specified process doesn&#8217;t exist?<\/h2>\n<p>If the process whose name is passed to killall isn&#8217;t running (doesn&#8217;t exist), then the tool conveys this to the user in output.<\/p>\n<p><a class=\"fancybox\" id=\"img-killall-no-process\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/killall-no-process.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/linux-killall-command-for-beginners-8-examples-4.png\" alt=\"prevent killall from complaining if specified process doesn&#039;t exist\" width=\"283\" height=\"57\" title=\"\"><\/a><\/p>\n<p>However, if you don&#8217;t want the tool to produce such output, then you can use the <strong>-q<\/strong> command line option.<\/p>\n<p><a class=\"fancybox\" id=\"img-killall-q-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/killall-q-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/02\/linux-killall-command-for-beginners-8-examples-5.png\" alt=\"killall -q command option\" width=\"310\" height=\"56\" title=\"\"><\/a><\/p>\n<p>So you can see the killall command stayed quiet when -q was used.<\/p>\n<h2 id=\"q-how-to-kill-all-processes-owned-by-a-user\">Q6. How to kill all processes owned by a user?<\/h2>\n<p>If the requirement is to kill all processes that a specific user owns, then you can use the <strong>-u<\/strong> option provided by killall. Needless to say, the option requires you to specify the username for the user as its input.<\/p>\n<p class=\"command\">killall -u [user-name]\n<p>For example:<\/p>\n<p class=\"command\">killall -u himanshu<\/p>\n<h2 id=\"q-how-to-kill-processes-based-on-time\">Q7. How to kill processes based on time?<\/h2>\n<p>Suppose you want to kill all processes that have now been running for more than 5 hours, then you can do this using the <strong>-o<\/strong> option in the following way:<\/p>\n<p class=\"command\">killall -o 5h<\/p>\n<p>Of course, you can specify process names if you don&#8217;t want to kill all processes. Similarly, if you want to kill processes than are, say, less than 4 hours old, then you can do that using the <strong>-y<\/strong> command line option.<\/p>\n<p class=\"command\">killall -y 4h<\/p>\n<p>Here&#8217;s how the man page explains these options:<\/p>\n<pre readability=\"20\">-o, --older-than<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Match only processes that are older (started\u00a0 before)\u00a0 the\u00a0 time<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 specified.\u00a0\u00a0 The\u00a0 time is specified as a float then a unit.\u00a0 The<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 units are\u00a0 s,m,h,d,w,M,y\u00a0 for\u00a0 seconds,\u00a0 minutes,\u00a0 hours,\u00a0 days,<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 weeks, Months and years respectively.<p>\u00a0-y, --younger-than<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Match\u00a0 only\u00a0 processes that are younger (started after) the time<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 specified.\u00a0 The time is specified as a float then a\u00a0 unit.\u00a0\u00a0 The<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 units\u00a0 are\u00a0 s,m,h,d,w,M,y\u00a0 for\u00a0 seconds,\u00a0 minutes,\u00a0 hours, days,<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 weeks, Months and years respectively.<\/p><\/pre>\n<h2 id=\"q-how-to-make-sure-killall-only-returns-after-processes-die\">Q8. How to make sure killall only returns after processes die?<\/h2>\n<p>After the signal is delivered by killall to the process, if you want to make sure the command only returns after the process dies, then you can do this using the <strong>-w<\/strong> command line option, which forces killall to wait.<\/p>\n<p class=\"command\">killall -w [process-name]\n<p>Here&#8217;s how the man page describes this option:<\/p>\n<pre>-w, --wait<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Wait\u00a0 for\u00a0 all killed processes to die.\u00a0 killall checks once per<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 second if any of the\u00a0 killed\u00a0 processes\u00a0 still\u00a0 exist\u00a0 and\u00a0 only<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 returns if none are left.\u00a0 Note that killall may wait forever if<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 the signal was ignored, had no effect, or if the\u00a0 process\u00a0 stays<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 in zombie state.<\/pre>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>Killall may not be a cakewalk for newbies, but it isn&#8217;t very complex as well. You need to practice the command line options it offers. We&#8217;ve discussed majority of them, so this tutorial should be a good starting point. Once you are done with these, you can read more about the command by heading to its <a href=\"https:\/\/linux.die.net\/man\/1\/killall\" 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>We&#8217;ve already discussed the\u00a0kill command that you can use in case you want to terminate processes in Linux. However, there exists another command line utility that you can use for the same purpose: killall. In this tutorial, we will discuss the basics of this command using some easy to understand examples. But before we do &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-2844","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2844","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=2844"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/2844\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=2844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=2844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=2844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}