{"id":200,"date":"2016-01-12T15:34:07","date_gmt":"2016-01-12T15:34:07","guid":{"rendered":"http:\/\/wp-p3d2tsa2xh.pairsite.com\/?p=200"},"modified":"2019-02-06T13:37:16","modified_gmt":"2019-02-06T18:37:16","slug":"paircloud-using-kill-killall-and-pkill","status":"publish","type":"ht_kb","link":"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/","title":{"rendered":"Using kill, killall, and pkill"},"content":{"rendered":"<p class=\"p1\"><span class=\"s1\"><a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/shared-hosting\/\"><p style=\"background-color:#1a3d6e !important;color:#fff;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">Shared<\/p><\/a> <a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/vps\/\"><p style=\"background-color:#1a3d6e !important;color:#fff;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">VPS<\/p><\/a> <a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/qs-dedicated\/\"><p style=\"background-color:#1a3d6e !important;color:#fff;padding:6px; display:inline-block!important;font-size:12px; font-weight:bold; border-radius:3px;\">Dedicated<\/p><\/a>\u00a0<a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/wp-professional\/\"><p style=\"background-color:#1a3d6e !important;color:#fff !important;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">WP Professional<\/p><\/a> <a style=\"color:#fff; text-decoration:none!important;\" href=\"https:\/\/www.pair.com\/support\/kb\/tags\/wp-professional-plus\/\"><p style=\"background-color:#1a3d6e !important;color:#fff !important;padding:6px; display:inline-block!important;font-size:12px;font-weight:bold; border-radius:3px;\">WP Professional Plus<\/p><\/a><\/span><\/p>\n<p>The kill command is in the format of <code>kill signal processid<\/code>.<br \/>\nThe kill and killall commands are used to kill the specified processes.<\/p>\n<div class=\"bs-callout bs-callout-danger\">\n<h4 class=\"text-danger\">Warning!<\/h4>\n<p>The kill and killall commands are extremely powerful. If they are misused they can bring a server down. If you are new to these two commands it is recommended that you learn on a non production server.<\/p>\n<\/div>\n<p>During this tutorial we will use the <code>ps<\/code>, <code>more<\/code> and the <code>grep<\/code> command. We will not cover the detailed usage of these commands but their usage should be self explanatory. Please see the relevant man pages for details.<\/p>\n<h3 class=\"kb\">What is a process?<\/h3>\n<p>A process is a running program in memory or part of a program. In its simplest form it is a complete program, however some programs such as Apache will spawn additional processes so that it can run many jobs in parallel across the multiple cores of the CPU. To help identify each process it is given a numeric ID starting with PID 1. PID 1 is the first process on a Linux server to be run and up until recently was always called init. This was the system initialization process and loaded all further programs.<\/p>\n<p>To view a list of running processes you can use the command <code>ps aux<\/code>. The <code>ps<\/code> command lists running processes. You can safely play around with the three options <code>a<\/code>,<code>u<\/code> and <code>x<\/code> in different combinations. However <code>ps aux<\/code> gives you most details that you will require when managing a Linux system.<\/p>\n<p>If you try this command and the list is too long for your screen you can pipe it to more like this <code>ps aux | more<\/code>.<\/p>\n<p>If you want to filter the list use <code>ps aux | grep [process name]<\/code>. For example to see all apache processes use <code>ps aux | grep apache<\/code> or <code>ps aux | grep httpd<\/code> depending on what family of Linux you are using.<\/p>\n<h2>PSTREE<\/h2>\n<p>The ps command is a great command but sometimes as in the above case of Apache the parent process will have launched child processes using the same name. Sometimes you need to know the parent's process id (pid). The easiest way to do this is to use <code>pstree -p<\/code>. You can grep the output to show only the process you want to see by using <code>pstree -p | grep httpd<\/code>, which will result in something like this:<\/p>\n<pre>[root@plesk bare-theme]# pstree -p | grep httpd\r\n        |-httpd(31632)-+-httpd(10978)\r\n        |              |-httpd(10979)\r\n        |              |-httpd(10980)\r\n        |              |-httpd(10981)\r\n        |              |-httpd(10982)\r\n        |              |-httpd(10983)\r\n        |              |-httpd(10984)\r\n        |              |-httpd(10985)\r\n        |              `-httpd(10986)\r\n<\/pre>\n<p>As you can see in this example the first line has two httpd(pid). The top left one is the one you would send the signal to.<\/p>\n<h3 class=\"kb\">Using pgrep<\/h3>\n<p>Another way of finding the correct process id is to use <code>pgrep -l httpd<\/code>. This gives a cleaner output than pstree on its own. However in some circumstances it is preferable to use the <code>pstree <\/code>and filter through <code>grep<\/code>. <code>pgrep -l<\/code> is a handy one to remember. <code>pgrep<\/code> is generally most useful when used in combination with <code>pkill<\/code> (see later in this tutorial)<\/p>\n<h3 class=\"kb\">Kill Signals<\/h3>\n<p>What kill actually does is send a signal to the process. It doesn\u2019t actually kill it directly. The process is responsible for handling the signal. We will only look at a couple of signals in this tutorial. If you want to see the full list please use <code>kill -l<\/code>. If you want to get into the guts of signals please see <code>man 7 signal<\/code> however this is going well beyond the scope of this tutorial.<\/p>\n<p>The signals we will look at are SIGHUP (1), SIGKILL (9) and SIGTERM(15)<\/p>\n<h4>SIGHUP<\/h4>\n<p>This signal (HUP) was originally used in the days of dial up modems to let the process know that the serial line had been <strong>H<\/strong>ung <strong>UP<\/strong>. Because signals were so useful and back then there were no user defined signals, some programs that didn\u2019t require a terminal such as daemons would repurpose the HUP signal for other uses. This convention has been maintained to this day even though we now have custom signals available to us. The SIGHUP (1) signal is now used to tell a process to reload the configuration file and re-initialize. This is useful for services (Daemons) such as Apache. It is a much quicker way of restarting Apache with a new configuration. Using the results of the pstree as shown above we would issue the command <code>kill -HUP 31632<\/code>.<\/p>\n<h3>SIGTERM<\/h3>\n<p>The SIGTERM is the default signal sent by the kill command if you don\u2019t provide a signal. For instance kill 31632. This is the polite way of asking a process or program to stop. It is the preferred signal as it gives the process the opportunity to clean up after itself and shut down nicely.<\/p>\n<h3>SIGKILL<\/h3>\n<p>The SIGKILL signal tells the process to terminate immediately. The only time a process will not be able to comply is if it is in the middle of a system call such as writing a file. However when it returns from the system call it should process any queued signal. The SIGKILL (9) can be called by either <code>kill -KILL pid<\/code> or <code>kill -9 pid<\/code>. This signal is a hard kill and will terminate pretty much all running processes. The exception is that Zombie processes will not be affected by this. A Zombie process is a process that has finished and exited but for some reason still has an entry in the process table.<\/p>\n<h3 class=\"kb\">KILLALL<\/h3>\n<p>The killall command does the same as the kill command however it takes the name of the process instead of the process id (pid). It will then kill all the processes that share this name. In the above example we could use <code>killall httpd<\/code>. When using killall you can also send signals using the following format <code>killall -sKILL httpd<\/code>. This is a powerful command so if you want to be certain that you are not killing anything that you shouldn\u2019t be then use the -i interactive option <code>killall -sKILL -i httpd<\/code>. This will ask you y\/n before killing each pid.<\/p>\n<h3 class=\"kb\">pkill<\/h3>\n<p>The <code>pgrep<\/code> and <code>pkill<\/code> commands allow you to search for a process and kill a process by using a partial process name. For example if you are running a script <code>called very-long-script-name-that-you-cant-remember.sh<\/code> and you want to kill it without using ps to find the pid or typing in the full script name into <code>killall<\/code>. To kill this script you could use <code>pkill -9 very-long<\/code>. pkill and pgrep have some very useful options which you can read more about at <code>man pkill<\/code>. The pkill command requires that the name you use is part of the first 15 characters of the process name.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 The kill command is in the format of kill signal processid. The kill and killall commands are used to kill the specified processes. Warning! The kill and killall commands are extremely powerful. If they are misused they can bring a server down. If you are new to these two&#8230;<\/p>\n","protected":false},"author":12,"comment_status":"closed","ping_status":"open","template":"","format":"standard","meta":[],"ht-kb-category":[13],"ht-kb-tag":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using kill, killall, and pkill - Knowledge Base - Pair Networks<\/title>\n<meta name=\"description\" content=\"The kill command is in the format of kill signal processid.The kill and killall commands are used to stop the specified processes.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using kill, killall, and pkill - Knowledge Base - Pair Networks\" \/>\n<meta property=\"og:description\" content=\"The kill command is in the format of kill signal processid.The kill and killall commands are used to stop the specified processes.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowledge Base - Pair Networks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/pairnetworks\/\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-06T18:37:16+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@pairNetworks\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/\",\"name\":\"Using kill, killall, and pkill - Knowledge Base - Pair Networks\",\"isPartOf\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#website\"},\"datePublished\":\"2016-01-12T15:34:07+00:00\",\"dateModified\":\"2019-02-06T18:37:16+00:00\",\"description\":\"The kill command is in the format of kill signal processid.The kill and killall commands are used to stop the specified processes.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pair.com\/support\/kb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using kill, killall, and pkill\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#website\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/\",\"name\":\"Knowledge Base - Pair Networks\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pair.com\/support\/kb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#organization\",\"name\":\"Pair Networks\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg\",\"contentUrl\":\"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg\",\"width\":360,\"height\":360,\"caption\":\"Pair Networks\"},\"image\":{\"@id\":\"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/pairnetworks\/\",\"https:\/\/twitter.com\/pairNetworks\",\"https:\/\/www.instagram.com\/pairnetworks\/\",\"https:\/\/www.linkedin.com\/company\/2269676\/\",\"https:\/\/www.pinterest.com\/pairnetworksinc\/pins\/\",\"https:\/\/www.youtube.com\/user\/pairnetworks\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using kill, killall, and pkill - Knowledge Base - Pair Networks","description":"The kill command is in the format of kill signal processid.The kill and killall commands are used to stop the specified processes.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/","og_locale":"en_US","og_type":"article","og_title":"Using kill, killall, and pkill - Knowledge Base - Pair Networks","og_description":"The kill command is in the format of kill signal processid.The kill and killall commands are used to stop the specified processes.","og_url":"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/","og_site_name":"Knowledge Base - Pair Networks","article_publisher":"https:\/\/www.facebook.com\/pairnetworks\/","article_modified_time":"2019-02-06T18:37:16+00:00","twitter_card":"summary_large_image","twitter_site":"@pairNetworks","twitter_misc":{"Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/","url":"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/","name":"Using kill, killall, and pkill - Knowledge Base - Pair Networks","isPartOf":{"@id":"https:\/\/www.pair.com\/support\/kb\/#website"},"datePublished":"2016-01-12T15:34:07+00:00","dateModified":"2019-02-06T18:37:16+00:00","description":"The kill command is in the format of kill signal processid.The kill and killall commands are used to stop the specified processes.","breadcrumb":{"@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pair.com\/support\/kb\/paircloud-using-kill-killall-and-pkill\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pair.com\/support\/kb\/"},{"@type":"ListItem","position":2,"name":"Using kill, killall, and pkill"}]},{"@type":"WebSite","@id":"https:\/\/www.pair.com\/support\/kb\/#website","url":"https:\/\/www.pair.com\/support\/kb\/","name":"Knowledge Base - Pair Networks","description":"","publisher":{"@id":"https:\/\/www.pair.com\/support\/kb\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pair.com\/support\/kb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pair.com\/support\/kb\/#organization","name":"Pair Networks","url":"https:\/\/www.pair.com\/support\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg","contentUrl":"https:\/\/www.pair.com\/support\/kb\/wp-content\/uploads\/2022\/02\/Gb_TUkUE_400x400.jpeg","width":360,"height":360,"caption":"Pair Networks"},"image":{"@id":"https:\/\/www.pair.com\/support\/kb\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/pairnetworks\/","https:\/\/twitter.com\/pairNetworks","https:\/\/www.instagram.com\/pairnetworks\/","https:\/\/www.linkedin.com\/company\/2269676\/","https:\/\/www.pinterest.com\/pairnetworksinc\/pins\/","https:\/\/www.youtube.com\/user\/pairnetworks"]}]}},"_links":{"self":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/200"}],"collection":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/comments?post=200"}],"version-history":[{"count":4,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/200\/revisions"}],"predecessor-version":[{"id":6559,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb\/200\/revisions\/6559"}],"wp:attachment":[{"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/media?parent=200"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb-category?post=200"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/www.pair.com\/support\/kb\/wp-json\/wp\/v2\/ht-kb-tag?post=200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}