<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Computer Support &#187; top</title>
	<atom:link href="http://www.xiitec.com/blog/tag/top/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xiitec.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 30 Dec 2009 08:40:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Performance tools: top</title>
		<link>http://www.xiitec.com/blog/2008/02/12/using-rsync-for-local-file-transfers-and-synchronization/</link>
		<comments>http://www.xiitec.com/blog/2008/02/12/using-rsync-for-local-file-transfers-and-synchronization/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 18:11:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[top]]></category>

		<guid isPermaLink="false">http://www.xiitec.com/blog/?p=104</guid>
		<description><![CDATA[The top command is one of the most familiar performance tools. Most system administrators run  top to see how their Linux and UNIX systems are performing. The  top utility provides a great way to monitor the performance of  processes and Linux as a whole. top can be run as a normal user [...]]]></description>
			<content:encoded><![CDATA[<p>The top command is one of the most familiar performance tools. Most system administrators run  top to see how their Linux and UNIX systems are performing. The  top utility provides a great way to monitor the performance of  processes and Linux as a whole. top can be run as a normal user as well as root.</p>
<p><span id="more-104"></span>The top display has two parts. The first third or so shows information about Linux as a whole.  The remaining lines are filled with individual process information. If  the window is stretched, more processes are shown to fill the screen.</p>
<p>Much general Linux information can be obtained by using several  other commands instead of top.  It is nice to have it all on one screen from one command, though. The  first line shows the load average for the last one, five, and fifteen  minutes. Load average indicates how many processes are running on a CPU  or waiting to run. The uptime command can be used to display  load averages as well. Next comes process information, followed by CPU,  memory, and swap. The memory and swap information is similar to the free command output. After we determine memory  and CPU usage, the next question is, which processes are using it?</p>
<p>Most of the process information can be obtained from the  ps command too, but top provides a nicer format that is easier  to read. The most useful interactive top command is h for  help, which lists top&#8217;s other interactive commands.</p>
<p><strong></p>
<p>Output Explained</strong></p>
<p>Let&#8217;s take a look at what the information from top  means. We&#8217;ll use the following output from top as an example:</p>
<pre>16:30:30  up 16 days,  7:35,  2 users,  load average: 0.54, 0.30, 0.11
73 processes: 72 sleeping, 1 running, 0 zombie, 0 stopped
CPU states:  cpu    user    nice  system    irq  softirq  iowait     idle
           total   13.3%    0.0%   20.9%   0.0%   0.0%    0.0%    65.7%
Mem:   511996k av,  498828k used,   13168k free,  0k shrd,  59712k buff
                    387576k actv,   68516k in_d,  9508k in_c
Swap:  105832k av,    2500k used,  103332k free            343056k cached  PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME CPU COMMAND
10250 dave      20   0  1104 1104   888 R     3.8  0.2   0:00   0 top
10252 root      23   0   568  568   492 S     0.9  0.1   0:00   0 sleep
    1 root      15   0   512  512   452 S     0.0  0.1   0:04   0 init</pre>
<pre></pre>
<p>The first line from top displays the load average  information:</p>
<pre>16:30:30 up 16 days, 7:35, 2 users, load average: 0.54, 0.30, 0.11</pre>
<p>This output is similar to the output from uptime.  You can see how long Linux has been up, the time, and the number of  users. The 1-, 5-, and 15-minute load averages are displayed as well.  Next, the process summary is displayed:</p>
<pre>73 processes: 72 sleeping, 1 running, 0 zombie, 0 stopped</pre>
<p>We see 73 total processes. Of those, 72 are sleeping, and one is  running. There are no zombies or stopped processes. A process becomes a  zombie when it exits and its parent has not waited for it with the wait(2) or waitpid(2)  functions. This often happens because the parent process exits before  its children. Zombies don&#8217;t take up resources other than the entry in  the process table. Stopped processes are processes that have been sent  the STOP signal. See the signal(7) man page for more  information.</p>
<p>Next up is the CPU information:</p>
<pre>CPU states:  cpu  user   nice  system   irq  softirq  iowait   idle
           total 13.3%   0.0%   20.9%  0.0%     0.0%    0.0%  65.7%</pre>
<p>The CPU lines describe how the CPUs spend their time. The  top command reports the percentage of CPU time spent in user or kernel  mode, running niced processes, and in idleness. The iowait  column shows the percentage of time that the processor was waiting for  I/O to complete while no process was executing on the CPU. The irq and softirq  columns indicate time spent serving hardware and software interrupts. Linux  kernels earlier than 2.6 don&#8217;t report irq, softirq, and  iowait.</p>
<p>The memory information is next:</p>
<pre>Mem: 511996k av, 498828k used, 13168k free,   0k shrd,  59712k buff
                 387576k actv, 68516k in_d,   9508k in_c</pre>
<p>The first three metrics give a summary of memory  usage. They list total usable memory, used memory, and free memory.  These are all you need to determine whether Linux is low on memory.</p>
<p>The next five metrics identify how the used memory is allocated. The shrd field shows shared memory usage and  buff is memory used in buffers. Memory that has been allocated to the  kernel or user processes can be in three different states:  active, inactive dirty, and inactive clean. Active,  actv in top, indicates that the memory has been used recently.  Inactive dirty, in_d in top,  indicates that the memory has not been used recently and may be  reclaimed. In order for the memory to be reclaimed, its contents must  be written to disk. This process is called &#8220;laundering&#8221; and can be  called a fourth temporary state for memory. Once laundered, the  inactive dirty memory becomes inactive clean, in_c in  top.</p>
<p>The swap information is next:</p>
<pre>Swap: 105832k av, 2500k used, 103332k free   343056k cached</pre>
<p>The av field is the total amount of swap  that is available for use, followed by the amount used and amount free.  Last is the amount of memory used for cache by the kernel.</p>
<p>The rest of the top display is process  information:</p>
<pre>  PID USER    PRI NI SIZE  RSS SHARE STAT %CPU %MEM   TIME CPU COMMAND
10250 dave     20  0 1104 1104   888 R     3.8  0.2   0:00   0 top
10252 root     23  0  568  568   492 S     0.9  0.1   0:00   0 sleep
    1 root     15  0  512  512   452 S     0.0  0.1   0:04   0 init</pre>
<pre></pre>
<p><strong>Saving Customization</strong></p>
<p>A very nice top feature is the capability  to save the current configuration. Change the display as you please  using the interactive commands and then press w to save the view. top writes a  .toprc file in the user&#8217;s home directory that saves the configuration.  The next time this user starts top, the same display options are  used.</p>
<p>top also looks for a default configuration file, /etc/toprc. This file is a global configuration file  and is read by top when any user runs the utility. This file can be  used to cause top  to run in secure mode and also to set the refresh delay. Secure mode  prevents non-root users from killing or changing the nice value of  processes. It also prevents non-root users from changing the refresh  value of top. A sample /etc/toprc file for our Red Hat  Enterprise Linux ES release 3 looks like the following:</p>
<pre>$ cat /etc/toprc
s3</pre>
<p>The s indicates secure mode, and  the 3 specifies three-second refresh intervals. Other distributions may  have different formats for /etc/toprc. The capability to kill processes  is a pretty nice feature. If some user has a runaway process, the top  command makes it easy to find and kill. Run top, show all the processes  for a user with the u command, and then use k to kill it.  top not only is a good performance monitoring tool, but it can also be used to improve  performance by killing those offensive processes.</p>
<p><strong>Batch Mode</strong></p>
<p>top can also be run in batch mode. Try running the  following command:</p>
<pre>$ top n 1 b &gt;/tmp/top.out</pre>
<p>The -n 1 tells top to only show one  iteration, and the -b option indicates that the output should be in  text suitable for writing to a file or piping to another program such as  less. Something like the following two-line script would make a nice  cron job:</p>
<pre># cat /home/dave/top_metrics.sh
echo "**** " 'date' " ****" &gt;&gt; /var/log/top/top.'date +%d'.out
/usr/bin/top -n 1 -b &gt;&gt; /var/log/top/top.'date +%d'.out</pre>
<p>We could add it to crontab and collect output every 15  minutes.</p>
<pre># crontab -l
*/15 * * * * /home/dave/top_metrics.sh</pre>
<p>The batch output makes it easy to take a thorough  look at what is running while enjoying a good cup of coffee. All the  processes are listed, and the output isn&#8217;t refreshing every five  seconds. If a .toprc  configuration file exists in the user&#8217;s home directory, it is used to format the  display. The following output came from the top batch mode running on a  multi-CPU Linux server. Note that we don&#8217;t show all 258 processes from the  top output.</p>
<pre>10:17:21  up 125 days, 10:10,  4 users,  load average: 3.60, 3.46, 3.73
258 processes: 252 sleeping, 6 running, 0 zombie, 0 stopped
CPU states:  cpu    user    nice  system    irq  softirq  iowait    idle
           total   41.0%    0.0%   21.4%   0.4%     0.4%    0.0%   36.5%
           cpu00   36.7%    0.0%   22.6%   1.8%     0.0%    0.0%   38.6%
           cpu01   46.2%    0.0%   17.9%   0.0%     0.9%    0.0%   34.9%
           cpu02   32.0%    0.0%   28.3%   0.0%     0.0%    0.0%   39.6%
           cpu03   49.0%    0.0%   16.9%   0.0%     0.9%    0.0%   33.0%
Mem:  4357776k av, 4321156k used,   36620k free,       0k shrd,  43860k buff
                   3261592k actv,  625088k in_d,   80324k in_c
Swap: 1048536k av,  191848k used,  856688k free          3920940k cached  PID USER    PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM     TIME CPU COMMAND
17599 wwrmn    21   0  9160 6900  1740 R    12.2  0.1    0:01    1 logsw
 1003 coedev   15 -10 71128  65M 66200 S &lt;   8.0  1.5  414:42    2 vmware-vmx
17471 wwrmn    15   0 10116 7868  1740 S     6.8  0.1    0:12    2 logsw
17594 wwrmn    18   0  9616 7356  1740 R     4.4  0.1    0:01    0 logsw
 6498 coedev   25   0 43108  36M 33840 R     4.0  0.8   9981m    1 vmware-vmx
17595 wwrmn    17   0  8892 6632  1740 S     3.0  0.1    0:01    3 logsw
17446 wwrmn    15   0 10196 7960  1740 S     2.8  0.1    0:13    3 logsw
17473 wwrmn    15   0  9196 6948  1740 S     2.8  0.1    0:02    1 logsw
17477 wwrmn    15   0  9700 7452  1740 S     2.3  0.1    0:04    2 logsw
  958 coedev   15 -10 71128  65M 66200 S &lt;   2.1  1.5   93:53    3 vmware-vmx
 7828 coedev   15 -10 38144  33M 33524 S &lt;  1.8   0.7   4056m    1 vmware-vmx
 6505 coedev   25   0     0    0     0 RW   1.8   0.0   3933m    1 vmware-rtc
 7821 coedev   15 -10 38144  33M 33524 S &lt;  1.6   0.7   6766m    1 vmware-vmx
 6478 coedev   15 -10 43108  36M 33840 S &lt;  1.6   0.8   6224m    0 vmware-vmx
17449 wwrmn    15   0  9820 7572  1740 S    1.6   0.1    0:07    3 logsw
 7783 coedev   15   0 47420  15M  1632 S    1.4   0.3   1232m    3 vmware
 6497 coedev   15 -10 43108  36M 33840 S &lt;  0.9   0.8   3905m    1 vmware-vmx
 1002 coedev   15 -10 71128  65M 66200 S &lt;  0.9   1.5   59:54    2 vmware-vmx
17600 jtk      20   0  1276 1276   884 R    0.9   0.0   0:00     2 top
 7829 coedev   25   0 38144  33M 33524 R    0.7   0.7   6688m    0 vmware-vmx
    1 root     15   0   256  228   200 S    0.0   0.0    2:25    0 init</pre>
<p>By now you can see why top is such a popular  performance tool. The interactive nature of top and the ability to  easily customize the output makes it a great resource for identifying  problems.</p>
<pre></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.xiitec.com/blog/2008/02/12/using-rsync-for-local-file-transfers-and-synchronization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

