{"id":19699,"date":"2023-06-22T10:05:24","date_gmt":"2023-06-22T10:05:24","guid":{"rendered":"https:\/\/linuxways.net\/?p=19699"},"modified":"2023-06-22T10:05:24","modified_gmt":"2023-06-22T10:05:24","slug":"top-command-on-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/linux-commands\/top-command-on-linux\/","title":{"rendered":"top Command on Linux"},"content":{"rendered":"<p>In the Linux operating system, understanding how resources like CPU and memory are utilized is crucial for system optimization and troubleshooting. The <strong>top<\/strong> command is a highly effective tool for fulfilling this objective. It displays real-time information about the system\u2019s running processes and resource usage.<\/p>\n<p>However, this is not the only thing you get out of it, but a whole lot of information about your system. But the thing is that you understand how to use this command effectively and how you read the results; that&#8217;s what matters the most. So, let&#8217;s get into it directly and see what it holds for us.<\/p>\n<h2><strong>What is the top Command?<\/strong><\/h2>\n<p>On Linux systems, both system administrators and regular users commonly rely on the <strong>top<\/strong> command. Essentially, it&#8217;s a real-time monitoring tool that provides a dynamic, live view of the processes running on a system.<\/p>\n<p>When you run the top command in your terminal, it pulls up a dashboard with a plethora of information. This information includes a list of all the running processes, along with details such as their Process IDs (PIDs), the user running them, CPU usage, memory usage, and more.<\/p>\n<p>Furthermore, it allows you to perform actions and control the processes directly from the interface. For instance, you can terminate processes, change their priorities, and even control the refresh rate of the information displayed.<\/p>\n<p>Turns out, it is essential for system monitoring and managing processes, especially when you need to make real-time decisions.<\/p>\n<h2><strong>Installing top Command on Linux<\/strong><\/h2>\n<p>Generally, the top command comes pre-installed with most Linux distributions. However, in case it&#8217;s not available, or if you&#8217;re using a minimal installation, here\u2019s how you can install it:<\/p>\n<h3><strong>1: Update Package List:<\/strong><\/h3>\n<p>Before installing any new software, it&#8217;s a good practice to update the package list so that you get the latest version. Open your terminal and type the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">apt-get update<\/span><\/div><\/div>\n<p><strong><em><img loading=\"lazy\" decoding=\"async\" width=\"722\" height=\"152\" class=\"wp-image-19703\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19699-1-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19699-1-1.png 722w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19699-1-1-300x63.png 300w\" sizes=\"auto, (max-width: 722px) 100vw, 722px\" \/><\/em><\/strong><\/p>\n<p>This command updates the list of packages and their versions but doesn&#8217;t install or upgrade any.<\/p>\n<h3><strong>2: Install the top Command:<\/strong><\/h3>\n<p>Now that your package list is up-to-date let&#8217;s install the top command. Type the following command in the terminal and hit Enter:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">apt-get install<\/span> procps<\/div><\/div>\n<p><em><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"95\" class=\"wp-image-19704\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19699-2-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19699-2-1.png 720w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19699-2-1-300x40.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/em><\/p>\n<p>Remember, if you are not using a Debian-based system (like Ubuntu), the package manager might be different. For Red Hat-based distributions (like Fedora and CentOS), use:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">yum install<\/span> procps-ng<\/div><\/div>\n<p>Here, <strong>procps<\/strong> is a package that contains the top command along with some other process monitoring tools.<\/p>\n<h3><strong>3: Verify the Installation:<\/strong><\/h3>\n<p>Once the installation is complete, it\u2019s good to verify that the top command has been successfully installed. Type <strong>top<\/strong> in your terminal and press Enter. If you see a screen with a list of processes and their resource usage, congratulations! You&#8217;ve successfully installed the top command.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"729\" height=\"441\" class=\"wp-image-19705\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19699-3-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19699-3-1.png 729w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/06\/word-image-19699-3-1-300x181.png 300w\" sizes=\"auto, (max-width: 729px) 100vw, 729px\" \/><\/p>\n<h3><strong>4: Learn from the manual<\/strong><\/h3>\n<p>Having installed the top command, it&#8217;s beneficial to understand its fundamental operation. Type <strong>man top<\/strong> in your terminal to access the manual page, which provides detailed information on how to use the top command.<\/p>\n<h2><strong>Using the top Command<\/strong><\/h2>\n<p>Now that you have the top command installed let&#8217;s dive into how to actually use it.<\/p>\n<h3><strong>1: Running top Command<\/strong><\/h3>\n<p>Starting the top command is easy. Open your terminal and simply type <strong>top<\/strong>, then press Enter. You will witness an up-to-the-minute presentation of active processes and the extent to which they utilize CPU and memory resources. To sort processes by CPU usage, just press the \u2018P\u2019 key.<\/p>\n<h3><strong>2: Reading the Output<\/strong><\/h3>\n<p>Now, let&#8217;s analyze and examine what you are observing.. At the uppermost section, you will see a concise overview of your system&#8217;s current state. It shows you:<\/p>\n<ul>\n<li>How long your system has been running (uptime)<\/li>\n<li>How many users are logged in<\/li>\n<li>The load average (a measure of system activity)<\/li>\n<li>How many tasks are running or sleeping<\/li>\n<li>CPU usage<\/li>\n<li>Memory usage<\/li>\n<\/ul>\n<p>In the following section, you will find a roster of active processes. Each line represents a single process. Here\u2019s what the columns mean:<\/p>\n<ul>\n<li><strong>PID<\/strong>: The process ID \u2013 a unique number for each process.<\/li>\n<li><strong>USER<\/strong>: Who started the process \u2013 usually your username or the system.<\/li>\n<li><strong>PR<\/strong>: Priority of the process.<\/li>\n<li><strong>VIRT<\/strong>: Virtual memory used by the process.<\/li>\n<li><strong>RES<\/strong>: Physical memory used by the process.<\/li>\n<li><strong>SHR<\/strong>: Shared memory used by the process.<\/li>\n<li><strong>S<\/strong>: Process status, like sleeping (S) or running (R).<\/li>\n<li><strong>%CPU<\/strong>: How much of the CPU the process is using.<\/li>\n<li><strong>%MEM<\/strong>: How much memory the process is using.<\/li>\n<li><strong>TIME+<\/strong>: How much CPU time the process has consumed.<\/li>\n<li><strong>COMMAND<\/strong>: The command&#8217;s name that initiated this process..<\/li>\n<\/ul>\n<h3><strong>3: Killing a Process<\/strong><\/h3>\n<p>Sometimes a process goes rogue, and you need to shut it down. To do this, press the &#8216;<strong>k<\/strong>&#8216; key, input the PID of the desired process to terminate, and subsequently press Enter.. Be careful with this \u2013 you don&#8217;t want to shut down something important by mistake!<\/p>\n<h3><strong>4: Changing the Priority of a Process<\/strong><\/h3>\n<p>Maybe you don&#8217;t need to shut a process down, but you want it to use less CPU. You can change its priority by pressing &#8216;r,&#8217; entering the PID, and then setting the new nice value (between -20 and 19, where -20 is the highest priority).<\/p>\n<h3><strong>5: Exiting top Command<\/strong><\/h3>\n<p>Done monitoring? To exit the top command, just press \u2018<strong>q<\/strong>\u2019 or &#8216;<strong>Ctrl+C<\/strong>.&#8217;<\/p>\n<h2><strong>Conclusion <\/strong><\/h2>\n<p>The <strong>top<\/strong> command is essential for overseeing and administering processes on your system. It enables you to access real-time information regarding your system&#8217;s CPU usage, memory utilization, and other available resources. The top command is particularly helpful for system administrators and developers who need to ensure optimal performance.<\/p>","protected":false},"excerpt":{"rendered":"<p>Top command on Linux is a utility that allows you to view real-time data about your system\u2019s CPU usage, Process IDs, memory, and other resources.<\/p>","protected":false},"author":110,"featured_media":19706,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049],"tags":[],"class_list":["post-19699","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/19699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=19699"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/19699\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/19706"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=19699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=19699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=19699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}