{"id":475,"date":"2009-01-04T20:00:26","date_gmt":"2009-01-05T00:00:26","guid":{"rendered":"http:\/\/www.databook.bz\/?page_id=475"},"modified":"2016-01-22T09:59:51","modified_gmt":"2016-01-22T14:59:51","slug":"top","status":"publish","type":"page","link":"http:\/\/www.linux-databook.info\/?page_id=475","title":{"rendered":"top"},"content":{"rendered":"<h1>Overview<\/h1>\n<p>One of the first tools I use when performing problem determination is <strong>top<\/strong>. The top program is a very powerful little utility that provides a great deal of information about your running system. This includes data about memory usage, CPU loads and a list of running processes including the amount of CPU time and memory being utilized by each process.<\/p>\n<p>Top displays system information in near real-time, updating (be default) every three seconds. It is also interactive and the data columns to be displayed can be modified.<\/p>\n<h2>Output of top<\/h2>\n<p>A sample output from the top program is shown below. The output from top is divided into two sections which are called the &#8220;Summary&#8221; section,\u00a0 which is the top section of the output, and the &#8220;Task&#8221; section which is the lower portion of the output.<\/p>\n<h3>Summary Section<\/h3>\n<p>The Summary section of the output from top is an overview of the system status. The first line shows the system uptime and the 1, 5 and 15 minute load averages. The second line shows the number of tasks currently active and the status of each.<\/p>\n<p>The lines containing CPU statistics are shown next. There can be a single line which combines the statistics for all CPUs present in the system, or as in the example below, one line for each CPU; in the case of the computer used for the example this is a single quad core CPU. Press the <strong>1<\/strong> key to toggle between the consolidated display of CPU usage and the display of the individual CPUs. The data in these lines is displayed as percentages of the total CPU time available.<\/p>\n<p>The other fields for these CPU data have changed over time and I had a difficult time locating information about the last three as they are relatively new. So here is a description of all of these fields.<\/p>\n<ul>\n<li><strong>us: userspace &#8211;<\/strong> Applications and other programs running in user space, i.e., not in the kernel.<\/li>\n<li><strong>sy: system calls &#8211;<\/strong> Kernel level functions. This does not include CPU time taken by the kernel itself, just the kernel system calls.<\/li>\n<li><strong>ni: nice &#8211;<\/strong> Processes that are running at a positive nice level.<\/li>\n<li><strong>id: idle &#8211;<\/strong> Idle time, i.e., time not used by any running process.<\/li>\n<li><strong>wa: wait &#8211;<\/strong> CPU cycles that are spent waiting for I\/O to occur. This is wasted CPU time.<\/li>\n<li><strong>hi: hardware interrupts &#8211;<\/strong> CPU cycles that are spent dealing with hardware interrupts.<\/li>\n<li><strong>si: software interrupts &#8211;<\/strong> CPU cycles spent dealing with software-created interrupts such as system calls.<\/li>\n<li><strong>st: steal time &#8211;<\/strong> The percentage of CPU cycles that a virtual CPU waits for a real CPU while the hypervisor is servicing another virtual processor.<\/li>\n<\/ul>\n<p>The last two lines in the Summary section are memory usage. They show the physical memory usage including both RAM and swap space.<\/p>\n<blockquote>\n<pre><span style=\"font-size: 8pt;\">top - 09:47:38 up 13 days, 24 min,  6 users,  load average: 0.13, 0.04, 0.01\r\nTasks: 180 total,   1 running, 179 sleeping,   0 stopped,   0 zombie\r\nCpu0  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st\r\nCpu1  :  0.9%us,  0.9%sy,  0.0%ni, 98.1%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st\r\nCpu2  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st\r\nCpu3  :  1.0%us,  0.0%sy,  0.0%ni, 99.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st\r\nMem:   2056456k total,   797768k used,  1258688k free,    92028k buffers\r\nSwap:  4095992k total,       88k used,  4095904k free,   336252k cached\r\n\r\nPID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND\r\n6292 root     20   0 99.4m  32m 7808 S   12  1.6   9:07.65 X\r\n519 root      15  -5     0    0    0 S    1  0.0  18:20.23 ata\/2\r\n24947 root    20   0  2404 1052  788 R    1  0.1   0:00.19 top\r\n29674 dboth   20   0 36996  16m  13m S    1  0.8   9:46.76 kicker\r\n29793 dboth   20   0 36168  17m  13m S    1  0.9   0:07.17 konsole\r\n1 root        20   0  2112  636  544 S    0  0.0   0:05.01 init\r\n2 root        15  -5     0    0    0 S    0  0.0   0:00.21 kthreadd\r\n3 root        RT  -5     0    0    0 S    0  0.0   0:00.85 migration\/0\r\n4 root        15  -5     0    0    0 S    0  0.0   3:20.01 ksoftirqd\/0\r\n5 root        RT  -5     0    0    0 S    0  0.0   0:00.04 watchdog\/0\r\n6 root        RT  -5     0    0    0 S    0  0.0   0:32.28 migration\/1\r\n7 root        15  -5     0    0    0 S    0  0.0   3:30.32 ksoftirqd\/1\r\n8 root        RT  -5     0    0    0 S    0  0.0   0:00.00 watchdog\/1\r\n9 root        RT  -5     0    0    0 S    0  0.0   0:03.70 migration\/2\r\n10 root       15  -5     0    0    0 S    0  0.0   5:16.94 ksoftirqd\/2\r\n11 root       RT  -5     0    0    0 S    0  0.0   0:00.00 watchdog\/2\r\n12 root       RT  -5     0    0    0 S    0  0.0   0:00.56 migration\/3\r\n13 root       15  -5     0    0    0 S    0  0.0   2:54.63 ksoftirqd\/3\r\n14 root       RT  -5     0    0    0 S    0  0.0   0:00.00 watchdog\/3\r\n15 root       15  -5     0    0    0 S    0  0.0   0:03.55 events\/0\r\n16 root       15  -5     0    0    0 S    0  0.0   0:15.47 events\/1\r\n17 root       15  -5     0    0    0 S    0  0.0   0:05.17 events\/2\r\n18 root       15  -5     0    0    0 S    0  0.0   0:02.22 events\/3\r\n19 root       15  -5     0    0    0 S    0  0.0   0:00.00 khelper\r\n78 root       15  -5     0    0    0 S    0  0.0   0:01.32 kblockd\/0\r\n79 root       15  -5     0    0    0 S    0  0.0   0:00.39 kblockd\/1\r\n80 root       15  -5     0    0    0 S    0  0.0   0:00.41 kblockd\/2\r\n81 root       15  -5     0    0    0 S    0  0.0   0:13.20 kblockd\/3\r\n83 root       15  -5     0    0    0 S    0  0.0   0:00.00 kacpid\r\n84 root       15  -5     0    0    0 S    0  0.0   0:00.00 kacpi_notify\r\n164 root      15  -5     0    0    0 S    0  0.0   0:00.00 cqueue\r\n166 root      15  -5     0    0    0 S    0  0.0   0:00.00 ksuspend_usbd\r\n171 root      15  -5     0    0    0 S    0  0.0   0:00.11 khubd\r\n174 root      15  -5     0    0    0 S    0  0.0   0:00.00 kseriod\r\n226 root      15  -5     0    0    0 S    0  0.0   8:55.50 kswapd0<\/span><\/pre>\n<\/blockquote>\n<h3>Task Section<\/h3>\n<p>The Task section of the output from top is a listing of the running processes in the system \u2014 at least the for the number of processes, or tasks, for which there is room on the terminal display. The default columns displayed by top are described below. Several other columns are available and each can usually be added with a single keystroke; refer to the top man page for details.<\/p>\n<ul>\n<li><strong>PID &#8211; <\/strong>The Process ID.<\/li>\n<li><strong>USER &#8211;<\/strong> The username of the process owner.<\/li>\n<li><strong>PR &#8211;<\/strong> The priority of the process.<\/li>\n<li><strong>NI &#8211;<\/strong> The nice number of the process.<\/li>\n<li><strong>VIRT &#8211;<\/strong> The total amount of virtual memory allocated to the process.<\/li>\n<li><strong>RES &#8211;<\/strong> Resident size (in kb unless otherwise noted) of non-swapped physical memory consumed by a process.<\/li>\n<li><strong>SHR &#8211; <\/strong>The amount of shared memory in kb used by the task.<\/li>\n<li><strong>S &#8211;<\/strong> The status of the task. This can be R for running, S for sleeping, and Z for zombie. Less frequently seen statuses can be T for traced or stopped, and D for uninterruptible sleep.<\/li>\n<li><strong>%CPU &#8211; <\/strong>The percentage of CPU cycles, or time used by this task during the last measured time period. The default is three seconds but can be changed. Fractional seconds are allowed, but very small values can overload the system.<\/li>\n<li><strong>%MEM &#8211;<\/strong> The percentage of physical system memory used by the task.<\/li>\n<li><strong>TIME+ &#8211;<\/strong> Total CPU time to 100ths of a second consumed by the process since the task was started.<\/li>\n<li><strong>COMMAND &#8211; <\/strong>This is the command that was used to launch the task.<\/li>\n<\/ul>\n<p>Be sure to read the man page for top because there is a large amount of information about configuring and interacting with top. Also use the <strong>h<\/strong> key for help in interactive mode. This help can provide you with information about selecting and sorting the columns of data, setting the update interval and much more.<\/p>\n<h2>What top can tell you<\/h2>\n<p>The top program can tell you a great deal when you are looking for the cause of a problem. It can tell you when a process, and which one, is sucking up all the CPU time, whether there is enough free memory, whether processes are stalled while waiting for I\/O such as disk or network access to complete, and much more.<\/p>\n<p>Using the interactive &#8220;k&#8221; command top also allows you to kill processes that may be hogging CPU time.<\/p>\n<p>I strongly recommend that you spend time watching top running on a system while it is functioning normally so you will be able to differentiate those things that may be abnormal while you are looking for the cause of a problem.<\/p>\n<p>Remember, top is your friend!<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview One of the first tools I use when performing problem determination is top. The top program is a very powerful little utility that provides a great deal of information about your running system. This includes data about memory usage,&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/www.linux-databook.info\/?page_id=475\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":381,"menu_order":8,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-475","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages\/475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=475"}],"version-history":[{"count":31,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages\/475\/revisions"}],"predecessor-version":[{"id":711,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages\/475\/revisions\/711"}],"up":[{"embeddable":true,"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=\/wp\/v2\/pages\/381"}],"wp:attachment":[{"href":"http:\/\/www.linux-databook.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}