|Contents||Bulletin||Scripting in shell and Perl||Network troubleshooting||History||Humor|
|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:
January 4, 2010 | http://www.thegeekstuff.com/
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.
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.
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.
Top output by default shows CPU line for all the CPUs combined together as shown below.
By default, linux top command updates the output every 3.0 seconds. When you want to update the output on-demand, press space bar.
Press z or b, which will highlight all running process as shown below.
If you want to execute top command in the batch mode use option -b as shown below.
May 16, 2008 | The Joel on Software Discussion GroupUnder '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.Graham Allan:
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.
VIRT = SWAP + RES.
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.
RES = CODE + DATA.
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...
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.
top (Unix) - Wikipedia, the free encyclopedia
top - Linux Command - Unix Command
How do I Use the Unix Top Command
Linux and Unix top command help
iftop- a similar tool for monitoring bandwidth usage
powerTOP- a similar tool for monitoring power usage
latencyTOP- a similar tool for monitoring latency
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.-d delay
Show command line in display instead of just command name.-f
Specify delay between refreshes.-h
Add or remove fields or columns.-i
Print a help message and exit.-n num
Suppress display of idle and zombie processes. -i is a toggle; top starts with the last remembered setting.-p pid
Update display num times, then exit.-s
Monitor only processes with the specified process ID.-S
Secure mode. Disable some (dangerous) interactive commands.-u user
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.-v
Monitor only processes with the specified UID or username, matching real, effective, saved, and filesystem ids.
Print version information and exit.
Remove restrictions on which tasks are shown. Reverses the effect of an active i or n command.<, >
Update display immediately.A
Move the sort field. Use < to move one column left and > to move one column to the right.b
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.B
Toggle between bold and reverse display. Only works with x or y.c
Globally toggle bold display.d, s
Toggle display of command name or full command line.f
Change delay between refreshes. Prompt for new delay time, which should be in seconds. Suppressed in secure mode.F, O
Prompt to add fields to or remove fields from the display.G
Select sort field.h, ?
Select another field group and make it current, or change by selecting a number from the following list:12
Display help about commands and the status of secure and cumulative modes.k
Toggle SMP view. Use I to toggle IRIX/Solaris mode, 1 to toggle single/separate states.i
Prompt for process ID to kill, and signal to send (default is 15) to kill it.l
Toggle suppression of idle and zombie processes.m
Toggle display of load-average and uptime information.n, #
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).o
Sort numerically by process ID.P
Prompt to change order of displayed fields.q
Sort tasks by CPU usage (default).r
Apply renice to a process. Prompt for PID and renice value. Suppressed in secure mode.S
Toggle normal or reverse sort.t
Toggle cumulative mode. (See the -S option.)T
Toggle display of processes and CPU states lines.u
Sort tasks by time/cumulative time.W
Prompt for specific user to show.x
Write current setup to ~/.toprc. This is the recommended way to write a top configuration file.y
Toggle highlighting for sort field.z
Toggle highlights for running tests.Z
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.a
Show all invisible windows or hide all visible windows.g
Cycle forward through all four windows.w
Change the name of the current window or group.
Cycle backward through all four windows.
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.Cpu(s)
The total number of processes running when the last update was taken, shown as the number of running, sleeping, stopped, or undead tasks.Mem
The percentage of CPU time spent in user mode, in system mode, on tasks with a negative nice value, and idle.Swap
Memory statistics, including total available memory, free memory, memory used, shared memory, and memory used for buffers.PID
Swapspace statistics, including total, available, used, and cached.PPID
Parent process ID.USER
Effective user ID of task's owner.RUSER
Effective username of task's owner.GROUP
Real username of task's owner.PR
The effective group name of task's owner.NI
Page fault count.DATA
Data plus stack size.SWAP
Resident task size.VIRT
Size of swapped-out portion of task.nDRT
The total amount of virtual memory used by the task.#C
Size of pages marked dirty.SHR
Last-used processor, for multiprocessor systems.S
Amount of shared memory used.WCHAN
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).TIME
Address or name of the kernel function in which the task is currently sleeping.TIME+
Total CPU time used by task and any children.%CPU
Like TIME, but shows the time down to hundredths of a second.%MEM
Share of CPU time since last update, as percentage of total CPU time.TTY
Share of physical memory.COMMAND
Command line (truncated if too long) if task is in memory, or command name in parentheses if swapped out.
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 ss.tt (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.
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.
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 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 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
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)
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 quotes : Somerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose Bierce : Bernard 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 DOS : Programming Languages History : PL/1 : Simula 67 : C : History of GCC development : Scripting 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
The Peter Principle : Parkinson Law : 1984 : The Mythical Man-Month : How to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s 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
|You can use PayPal to make a contribution, supporting hosting of this site with different providers to distribute and speed up access. Currently there are two functional mirrors: softpanorama.info (the fastest) and softpanorama.net.|
The statements, views and opinions presented on this web page are those of the author 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: February 19, 2014