{"id":751,"date":"2017-12-23T09:52:33","date_gmt":"2017-12-23T04:22:33","guid":{"rendered":"https:\/\/www.coimbatorewebhosting.com\/blog\/?p=751"},"modified":"2017-12-23T10:41:04","modified_gmt":"2017-12-23T05:11:04","slug":"top-process-management-commands-in-linux","status":"publish","type":"post","link":"https:\/\/coimbatorewebhosting.com\/blog\/top-process-management-commands-in-linux\/","title":{"rendered":"Top Process Management Commands in Linux."},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-process-management-commands-in-linux\/#Introduction\" >Introduction:-<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-process-management-commands-in-linux\/#where_we_use_this_or_run_into\" >where we use this or run into :-<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-process-management-commands-in-linux\/#top_command_in_linux\" >top command in linux:-<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-process-management-commands-in-linux\/#htop_command_in_Linux\" >htop command in Linux:-<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-process-management-commands-in-linux\/#Command_to_List_process_ps\" >Command to List process ps :-<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-process-management-commands-in-linux\/#Command_pstree\" >Command pstree :-<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-process-management-commands-in-linux\/#Command_nice_-_to_change_process_priorities\" >Command&nbsp;nice :- to change process priorities<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-process-management-commands-in-linux\/#command_renice\" >command renice:-<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-process-management-commands-in-linux\/#Command_pgrep\" >Command&nbsp;pgrep :-<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/coimbatorewebhosting.com\/blog\/top-process-management-commands-in-linux\/#Command_kill\" >Command kill :-<\/a><\/li><\/ul><\/nav><\/div>\n<h4><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction:-<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>when we run an any application or a program in a linux server it will create an instance is called process.<br \/>\nHere in this article we can see and discuss the process management commands one by one.<br \/>\nThe basic commands are<br \/>\nTOP<br \/>\nHTOP<br \/>\nPS<br \/>\nPSTREE<br \/>\nPGREP<br \/>\nNICE<br \/>\nRENICE<br \/>\nand KILL command.<\/p>\n<p>Each and every process uses server resources like memory, storage and computing resources to complete the job associated with each process.<\/p>\n<p>Every time a new process is started it is assigned an identification number (ID) which is called process ID or PID in short.<\/p>\n<p>As as Linux Admin or user, we will run into situations where we need to manage all these processes. That\u2019s where the Linux operating system provides a lot of tools to manage running processes.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"where_we_use_this_or_run_into\"><\/span>where we use this or run into :-<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li>List the top running processes and server resource snapshot<\/li>\n<li>To view all the running processes on Linux<\/li>\n<li>To see resources used by each process<\/li>\n<li>Change process priorities and resources available to processes.<\/li>\n<li>Find specific process and change state of that process<\/li>\n<li>Killing running or run away processes<\/li>\n<\/ul>\n<p>The above is the situation or scenarios where we use the linux process management commands.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"top_command_in_linux\"><\/span>top command in linux:-<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>The most easiest and essential command for every Linux user is TOP. As the name indicates it displays overall view of the Linux system including TOP running processes.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-752\" src=\"https:\/\/www.coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/nice-3.jpg\" alt=\"\" width=\"1344\" height=\"729\" srcset=\"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/nice-3.jpg 1344w, https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/nice-3-300x163.jpg 300w, https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/nice-3-768x417.jpg 768w, https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/nice-3-1024x555.jpg 1024w\" sizes=\"auto, (max-width: 1344px) 100vw, 1344px\" \/><\/p>\n<p>Here we can see server statistics like uptime, load averages and running processes states in the first few lines.<\/p>\n<p>It also shows top running processes with their process identification number(PID), process user, Priority, nice value, %CPU and %memory consumed by the process etc.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"htop_command_in_Linux\"><\/span>htop command in Linux:-<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Htop is similar to TOP but more advanced with an interactive process viewer. It shows CPU,Memory and SWAP resources as text graphs.<\/p>\n<p>Difference between htop and top:-<\/p>\n<ul>\n<li>In htop we can scroll the list vertically and horizontally to see all processes and full command lines.<\/li>\n<li>In top we are subject to a delay for each unassigned key you press (especially annoying when multi-key escape sequences are triggered by accident).<\/li>\n<li>htop starts faster (top seems to collect data for a while before displaying anything).<\/li>\n<li>In htop we don&#8217;t need to type the process number to kill a process, in top you do.<\/li>\n<li>In htop we don&#8217;t need to type the process number or the priority value to renice a process, in top you do.<\/li>\n<li>In htop we can kill multiple processes at once.<\/li>\n<li>top is older, hence, more tested.<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"Command_to_List_process_ps\"><\/span>Command to List process ps :-<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>&#8220;<span class=\"bold_text\">ps<\/span>&#8221; command is the most basic command to see all the running processes on the system. It outputs all running processes of specific user or all users.<\/p>\n<p><span class=\"bold_text\">To see running processes of existing user:<\/span><\/p>\n<pre>ps<\/pre>\n<p>The output will be like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-754\" src=\"https:\/\/www.coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/ps-1.jpg\" alt=\"\" width=\"234\" height=\"82\"><\/p>\n<p>To see running processes of all users:<\/p>\n<pre>ps -aux<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-756\" src=\"https:\/\/www.coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/ps-aux.jpg\" alt=\"\" width=\"1359\" height=\"580\" srcset=\"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/ps-aux.jpg 1359w, https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/ps-aux-300x128.jpg 300w, https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/ps-aux-768x328.jpg 768w, https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/ps-aux-1024x437.jpg 1024w\" sizes=\"auto, (max-width: 1359px) 100vw, 1359px\" \/><\/p>\n<p>To view specific service\/user running processes:<\/p>\n<pre>ps -ef | grep httpd<\/pre>\n<div class=\"thrv_paste_content thrv_wrapper tve_empty_dropzone\">\n<h4><span class=\"ez-toc-section\" id=\"Command_pstree\"><\/span><span class=\"bold_text\">Command pstree :-<\/span><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>This \u201c<span class=\"bold_text\">pstree<\/span>\u201d command will be useful if we want to see the running processes hierarchically arranged in tree format.<\/p>\n<p>It\u2019s very easy to understand parent and child processes using this command. It is used as a more visual alternative to the ps command. The root of the tree is either init or the process with the given pid.<\/p>\n<\/div>\n<div class=\"thrv_paste_content thrv_wrapper tve_empty_dropzone\">\n<h4><span class=\"ez-toc-section\" id=\"Command_nice_-_to_change_process_priorities\"><\/span>Command&nbsp;nice :- to change process priorities<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p><span class=\"bold_text\">This nice<\/span>&nbsp;command is used to assign particular priority, thus giving the process more or less CPU time than other processes.<\/p>\n<p>Process priority values range from&nbsp;<span class=\"bold_text\">-20 to 19<\/span>. Lower the nice value, higher the priority. The default nice value is 0.<\/p>\n<p>It means -20 has highest priority over 15. In order to use higher priorities (negative nice values) administrator privileges are required.<\/p>\n<p>When you use the command nice you start a new process and assign it priority (nice) value at the same time.<\/p>\n<pre>nice -3 top<\/pre>\n<p>The above command is used to starts the top command or process with nice value of -3.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"command_renice\"><\/span>command renice:-<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>This&#8221;<span class=\"bold_text\">renice<\/span>&#8221; command is used to change priorities of already running processes.<\/p>\n<p>In the above nice example we started process TOP with -3 priority. Let\u2019s change that priority using renice.<\/p>\n<p>syntax:<\/p>\n<pre> renice -n -p -PID<\/pre>\n<p>Command:<\/p>\n<pre>renice -5 -p 25476<\/pre>\n<p>when we enter the above command the output is like this,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-755\" src=\"https:\/\/www.coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/renice-5.jpg\" alt=\"\" width=\"412\" height=\"38\" srcset=\"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/renice-5.jpg 412w, https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/renice-5-300x28.jpg 300w\" sizes=\"auto, (max-width: 412px) 100vw, 412px\" \/><\/p>\n<h4><span class=\"ez-toc-section\" id=\"Command_pgrep\"><\/span>Command&nbsp;pgrep :-<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>In Linux each process is assigned a process ID, or PID. This is how the operating system identifies and keeps track of processes.<\/p>\n<p>&#8220;<span class=\"bold_text\">pgrep<\/span>&#8221; is the useful command to get list of PID\u2019s for a particular service or program.<\/p>\n<p>For example: If you want to see list of all PID\u2019s of apache web service or httpd.<\/p>\n<pre>pgrep httpd<\/pre>\n<p>If we enter the above command we will get output with PID&#8217;s of httpd service.<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Command_kill\"><\/span>Command kill :-<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Every process in Linux responds to signals. Signals are commands or instructions to processes to terminate or modify their behavior.<\/p>\n<p>The default way to send signals to processes is through Kill command.<\/p>\n<p>The very common kill command syntax are:<\/p>\n<pre>kill &lt;pid&gt;<\/pre>\n<p>This sends the&nbsp;<span class=\"bold_text\">T<\/span><span class=\"bold_text\">ERM<\/span>&nbsp;signal to the process. The TERM signal tells the process to please terminate. This allows the program to perform clean-up operations and exit smoothly.<\/p>\n<p>If the program is misbehaving and does not exit when given the TERM signal, we can escalate the signal by passing the KILL signal:<\/p>\n<pre>kill -5 &lt;pid&gt;<\/pre>\n<p>we can send &#8220;-kill&#8221; instead of 5<\/p>\n<pre>killall -5 - httpd - all instances having the same process name<\/pre>\n<p>If we don\u2019t know the process ID, we can use pkill command which works by using process name instead of PID\u2019s.<\/p>\n<pre>pkill -5 firefox<\/pre>\n<p>The above command will kill firefox program by sending TERM signal.<\/p>\n<p>Conclusion:<\/p>\n<p>Linux process management is an essential task for each and every Linux administrator.<\/p>\n<p>All the above tools allows you to manage system resources efficiently.<\/p>\n<p>And all the above mentioned process management commands should work fine in all Linux OS like centos,Red hat,Ubuntu.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction:- when we run an any application or a program in a linux server it will create an instance is called process. Here in this article we can see and discuss the process management commands one by one. The basic commands are TOP HTOP PS PSTREE PGREP NICE RENICE and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":762,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-751","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-latest"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/coimbatorewebhosting.com\/blog\/wp-content\/uploads\/2017\/12\/tag-image.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pa2YU7-c7","_links":{"self":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=751"}],"version-history":[{"count":0,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/posts\/751\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media\/762"}],"wp:attachment":[{"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coimbatorewebhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}