May the source be with you, but remember the KISS principle ;-)
Contents Bulletin Scripting in shell and Perl Network troubleshooting History Humor

top command

News Books Recommended Links Reference nice netstat
uptime ps free pmap


System Activity Reporter (sar)   Admin Horror Stories Unix History Humor Etc

the top command is a system monitor tool that produces a frequently-updated list of processes. The top command was inspired by the monitor process/topcpu  command found in the VMS operating system. William LeFebvre wrote the first implementation of top in April 1984 for BSD 4.1 while a graduate student at Rice University. It was released as an Open source project under the BSD license, which allowed it to be included in numerous proprietary BSD and UNIX operating systems.

By default, the processes are ordered by percentage of CPU usage, with only the "top" CPU consumers shown. The top command shows how much processing power and memory are being used, as well as other information about the running processes. Some versions of top allow extensive customization of the display, such as choice of columns or sorting method.

The list is both real-time and interactive.

To exit top  press the q key. Useful interactive commands that you can use:

For more information see Reference

There are 3 general states your CPU can be in:

These three meta states can be further subdivided. For example, user space programs can be categorized as those running under their initial priority level or those running with a nice priority. Niceness is a way to tweak the priority level of a process so that it runs less frequently. The niceness level ranges from -20 (most favorable scheduling) to 19 (least favorable). By default processes on Linux are started with a niceness of 0. See our blog post Restricting process CPU usage using nice, cpulimit, and cgroups for more information on nice.

Top Visited
Past week
Past month


Old News ;-)

[Dec 07, 2015] Understanding Linux CPU stats

Let's take a step back. There are 3 general states your CPU can be in:

These three meta states can be further subdivided. For example, user space programs can be categorized as those running under their initial priority level or those running with a nice priority. Niceness is a way to tweak the priority level of a process so that it runs less frequently. The niceness level ranges from -20 (most favorable scheduling) to 19 (least favorable). By default processes on Linux are started with a niceness of 0. See our blog post Restricting process CPU usage using nice, cpulimit, and cgroups for more information on nice.

[Jun 27, 2010] Can You Top This 15 Practical Linux Top Command Examples

January 4, 2010 |
  1. Show Processes Sorted by any Top Output Column Press O

    By default top command displays the processes in the order of CPU usage. When the top command is running, press M (upper-case) to display processes sorted by memory usage as shown below.

    To sort top output by any column, Press O (upper-case O) , which will display all the possible columns that you can sort by as shown below.

    When the linux top command is running, Press R, which does the sort in reverse order.

  2. Kill a Task Without Exiting From Top Press k

    Once you've located a process that needs to be killed, press 'k' which will ask for the process id, and signal to send. If you have the privilege to kill that particular PID, it will get killed successfully.

  3. Renice a Unix Process Without Exiting From Top Press r

    Press r, if you want to just change the priority of the process (and not kill the process). This will ask PID for renice, enter the PID and priority.

  4. Display Selected User in Top Output Using top -u
  5. Display Only Specific Process with Given PIDs Using top -p
  6. Display All CPUs / Cores in the Top Output Press 1 (one)

    Top output by default shows CPU line for all the CPUs combined together as shown below.

  7. Refresh Unix Top Command Output On demand (or) Change Refresh Interval

    By default, linux top command updates the output every 3.0 seconds. When you want to update the output on-demand, press space bar.

  8. Highlight Running Processes in the Linux Top Command Output Press z or b

    Press z or b, which will highlight all running process as shown below.

  9. Display Absolute Path of the Command and its Arguments Press c
  10. Quit Top Command After a Specified Number of Iterations Using top -n
  11. Executing Unix Top Command in Batch Mode

    If you want to execute top command in the batch mode use option -b as shown below.

  12. Split Top Output into Multiple Panels Press A
  13. Get Top Command Help from Command Line and Interactively
  14.   ..........
  15. Decrease Number of Processes Displayed in Top Output Press n

UNIX 'Top' command

May 16, 2008 | The Joel on Software Discussion Group

Under 'Top' there are two columns: SIZE and RES

SIZE- refers to the virtual memory

RES- refers to the resident memory used in the RAM

It is ideal to ensure that RES value is as low as possible? And to keep the RES value far below the SIZE value?


Friday, The general wisdom is to create your swap partition to be twice the amount of ram you have, up to about 512MB swap (at least I've never bothered making a larger swap for my desktop machine).

Keep in mind that Linux will try to keep RAM as full as it possible can, so it will appear that you're hurting for RAM when you're really doing ok, the kernel is just attempting to keep the system running as quickly as possible.

I have no idea about the behavior of other unices.

Fake Programmer:

Some stuff from 'man top':

VIRT -- Virtual Image (kb)
The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out.


SWAP -- Swapped size (kb)
The swapped out portion of a task's total virtual memory image.

RES -- Resident size (kb)
The non-swapped physical memory a task has used.


Btw I don't have a 'SIZE' column when I run top, so YMMV.

But I think if you're looking for memory efficiency then I'm reasonably sure you want to be able to reduce RES as much as possible, and try to have SWAP as close as possible to RES.

The lower RES is, the less memory your program will need, the more consistently you can have SWAP approaching RES the more of your program is available to be swapped out, thereby reducing the drain on the system's memory. No idea how easy it would be to do this though; think it would require a pretty tight control over the compilation to have the most used code bundled into the smallest number of pages.

No doubt I'll probably be shot down over some gross inaccuracy, but hopefully I'm in the right vicinity of what you're asking...

Graham Allan:

What is your real problem?

Are you a programmer asking how to write your program efficiently so it is not a memory hog, or a system administrator asking how to slow the system down by increasing swapping and paging so it looks like you have plenty of unused memory?

Because the latter is a really bad idea. As Fake Programmer said, most systems use "spare" memory for caching in order to run faster. Are you sure this is not what you are seeing? This memory can be instantly freed if required by an application.

That said, there are legitimate reasons for wanting to limit memory usage by processes. Perhaps one memory hog is "crowding out" another application. You may be able to do this using startup parameters of the program itself, with java vm's and databases for example, or the operating system may provide resource controls.

Recommended Links



Linux Command Directory top

top [options]

Provide information (frequently refreshed) about the most CPU-intensive processes currently running. You do not need to include a - before options. See ps for explanations of the field descriptors.



Run in batch mode; don't accept command-line input. Useful for sending output to another command or to a file.


Show command line in display instead of just command name.

-d delay

Specify delay between refreshes.


Add or remove fields or columns.


Print a help message and exit.


Suppress display of idle and zombie processes. -i is a toggle; top starts with the last remembered setting.

-n num

Update display num times, then exit.

-p pid

Monitor only processes with the specified process ID.


Secure mode. Disable some (dangerous) interactive commands.


Cumulative mode. Print total CPU time of each process, including dead child processes.

-u user

Monitor only processes with the specified effective UID or username.

-U user

Monitor only processes with the specified UID or username, matching real, effective, saved, and filesystem ids.


Print version information and exit.

Interactive commands


Remove restrictions on which tasks are shown. Reverses the effect of an active i or n command.

space, Enter

Update display immediately.

<, >

Move the sort field. Use < to move one column left and > to move one column to the right.


Toggle alternate display mode between a single window or multiple windows. See the following section Alternate display mode commands for the commands that work with A.


Toggle between bold and reverse display. Only works with x or y.


Globally toggle bold display.


Toggle display of command name or full command line.

d, s

Change delay between refreshes. Prompt for new delay time, which should be in seconds. Suppressed in secure mode.


Prompt to add fields to or remove fields from the display.

F, O

Select sort field.


Select another field group and make it current, or change by selecting a number from the following list:









h, ?

Display help about commands and the status of secure and cumulative modes.

I, 1

Toggle SMP view. Use I to toggle IRIX/Solaris mode, 1 to toggle single/separate states.


Prompt for process ID to kill, and signal to send (default is 15) to kill it.


Toggle suppression of idle and zombie processes.


Toggle display of load-average and uptime information.


Toggle display of memory information.

n, #

Prompt for maximum number of processes to show. If 0 is entered, show as many as will fit on the screen (default).


Sort numerically by process ID.


Prompt to change order of displayed fields.


Sort tasks by CPU usage (default).




Apply renice to a process. Prompt for PID and renice value. Suppressed in secure mode.


Toggle normal or reverse sort.


Toggle cumulative mode. (See the -S option.)


Toggle display of processes and CPU states lines.


Sort tasks by time/cumulative time.


Prompt for specific user to show.


Write current setup to ~/.toprc. This is the recommended way to write a top configuration file.


Toggle highlighting for sort field.


Toggle highlights for running tests.


Toggle between color and mono display.


Globally change color mappings.

Alternate display mode commands


Rebalance tasks in the current window.


Rebalance tasks in every window.


Show or hide the current window.


Show all invisible windows or hide all visible windows.


Cycle forward through all four windows.


Change the name of the current window or group.


Cycle backward through all four windows.

Field descriptions

The first five entries in the following list describe the lines that appear at the top of the top display. The rest are the fields that can be displayed for each task (sizes are in kilobytes). Use the interactive f command to add or remove fields.


Display the time the system has been up, the number of users, and three load averages consisting of the average number of processes ready to run in the last 1, 5, and 15 minutes.


The total number of processes running when the last update was taken, shown as the number of running, sleeping, stopped, or undead tasks.


The percentage of CPU time spent in user mode, in system mode, on tasks with a negative nice value, and idle.


Memory statistics, including total available memory, free memory, memory used, shared memory, and memory used for buffers.


Swapspace statistics, including total, available, used, and cached.


Process ID.


Parent process ID.


Effective user ID of task's owner.


Effective username of task's owner.


Real username of task's owner.


The effective group name of task's owner.




Nice value.


Page fault count.


Code size.


Data plus stack size.


Resident task size.


Size of swapped-out portion of task.


The total amount of virtual memory used by the task.


Size of pages marked dirty.


Last-used processor, for multiprocessor systems.


Amount of shared memory used.


State of the task. Values are S (sleeping), D (uninterruptible sleep), R (running), Z (zombies), or T (stopped or traced), possibly followed by < (negative nice value), N (positive nice value), or W (swapped out).


Address or name of the kernel function in which the task is currently sleeping.


Total CPU time used by task and any children.


Like TIME, but shows the time down to hundredths of a second.


Share of CPU time since last update, as percentage of total CPU time.


Share of physical memory.


Controlling tty.


Command line (truncated if too long) if task is in memory, or command name in parentheses if swapped out.


Task flags.

About top

Display Linux tasks.


top -hv | -bcisS -d delay -n iterations -p pid [, pid ...]

The traditional switches '-' and whitespace are optional.

-b Batch mode operation
Starts top in 'Batch mode', which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set with the '-n' command-line option or until killed.
-c Command line/Program name toggle
Starts top with the last remembered 'c' state reversed. Thus, if top was displaying command lines, now that field will show program names, and visa versa. See the 'c' interactive command for additional information.
-d Delay time interval as: -d (seconds.tenths)
Specifies the delay between screen updates, and overrides the corresponding value in one's personal configuration file or the startup default. Later this can be changed with the 'd' or 's' interactive commands.

Fractional seconds are honored, but a negative number is not allowed. In all cases, however, such changes are prohibited if top is running in 'Secure mode', except for root (unless the 's' command-line option was used). For additional information on 'Secure mode' see topic 5a. SYSTEM Configuration File.

-h Help
Show library version and the usage prompt, then quit.
-i Idle Processes toggle
Starts top with the last remembered 'i' state reversed. When this toggle is Off, tasks that are idled or zombied will not be displayed.
-n Number of iterations limit as: -n number
Specifies the maximum number of iterations, or frames, top should produce before ending.
-u Monitor by user as: -u somebody
Monitor only processes with an effective UID or user name matching that given.
-U Monitor by user as: -U somebody
Monitor only processes with a UID or user name matching that given. This matches real, effective, saved, and filesystem UIDs.
-p Monitor PIDs as: -pN1 -pN2 ... or -pN1, N2 [,...]
Monitor only processes with specified process IDs. This option can be given up to 20 times, or you can provide a comma delimited list with up to 20 pids. Co-mingling both approaches is permitted.

This is a command-line option only. And should you wish to return to normal operation, it is not necessary to quit
and and restart top -- just issue the '=' interactive command.

-s Secure mode operation
Starts top with secure mode forced, even for root. This mode is far better controlled through the system configuration file (see topic 5. FILES).
-S Cumulative time mode toggle
Starts top with the last remembered 'S' state reversed. When 'Cumulative mode' is On, each process is listed with the cpu time that it and its dead children have used. See the 'S' interactive command for additional information regarding this mode.
-v Version
Show library version and the usage prompt, then quit.


When operating top, the two most important keys are help ('h' or '?') and quit ('q') key. Alternatively, you could simply use the traditional interrupt key ('^C') when you're done.


Running the above command would give you a display similar to the below example. While the tasks are being displayed you can use any of the startup commands listed after the below example output.

top - 20:50:55 up 167 days, 14:26, 82 users, load average: 0.13, 0.05, 0.01
Tasks: 3 total, 1 running, 2 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.0% user, 2.2% system, 0.0% nice, 97.8% idle
Mem: 514964k total, 507860k used, 7104k free, 30404k buffers
Swap: 1630588k total, 158708k used, 1471880k free, 275380k cached

3747 hope 11 0 2004 1608 1608 S 0.3 0.3 0:00.56 sshd 
22245 hope 10 0 688 676 672 S 0.0 0.1 0:00.06 csh 
14015 hope 10 0 1024 1024 848 R 0.0 0.2 0:00.00 top

Startup Defaults
The following startup defaults assume no configuration file, thus no user customizations. Even so, items shown with an
asterisk ('*') could be overridden through the command-line.

A Alt display Off (full-screen)
* d Delay time 3.0 seconds
I Irix mode On (no, 'solaris' smp)
* p PID monitoring Off
* s Secure mode Off (unsecured)
B Bold disable Off
l Load Avg/Uptime On (thus program name)
t Task/Cpu states On (1+1 lines, see '1')
m Mem/Swap usage On (2 lines worth)
1 Single Cpu On (thus 1 line if smp)
b Bold hilite On (not 'reverse')
* c Command line Off (name, not cmdline)
* i Idle tasks On (show all tasks)
R Reverse sort On (pids high-to-low)
* S Cumulative time Off (no, dead children)
x Column hilite Off (no, sort field)
y Row hilite On (yes, running tasks)
z color/mono Off (no, colors)


FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available in our efforts to advance understanding of environmental, political, human rights, economic, democracy, scientific, and social justice issues, etc. We believe this constitutes a 'fair use' of any such copyrighted material as provided for in section 107 of the US Copyright Law. In accordance with Title 17 U.S.C. Section 107, the material on this site is distributed without profit exclusivly for research and educational purposes.   If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner. 

ABUSE: IPs or network segments from which we detect a stream of probes might be blocked for no less then 90 days. Multiple types of probes increase this period.  


Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy


War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes


Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law


Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Haters Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least

Copyright 1996-2016 by Dr. Nikolai Bezroukov. was created as a service to the UN Sustainable Development Networking Programme (SDNP) in the author free time. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License.

The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to make a contribution, supporting development of this site and speed up access. In case is down you can use the at


The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

Last modified: September 12, 2017