I'm looking for somthing like top is to CPU usage. Is there a command line argument for top that does this? Currently, my memory is so full that even 'man top' fails with out of memory 🙂
Memory Usage – How to Find Which Processes Are Taking All the Memory
memoryprocesstop
Related Solutions
You can use tstime to measure the highwater memory usage (RSS and virtual) of a process.
For example:
$ tstime date
Tue Aug 16 21:35:02 CEST 2011
Exit status: 0
pid: 31169 (date) started: Tue Aug 16 21:35:02 2011
real 0.017 s, user 0.000 s, sys 0.000s
rss 888 kb, vm 9764 kb
It also supports a more easy to parse output mode (-t
).
NOTE: Assuming you have this version of top
(procps). You can check with this command:
$ top --version
top: procps version 3.2.8
usage: top -hv | -bcisSH -d delay -n iterations [-u user | -U user] -p pid [,pid ...]
procps is often the version of top
included with Fedora/CentOS/RHEL and other variants.
Changing columns
If you look in the man page for top
you'll see a section titled: "2b. SELECTING and ORDERING Columns". There are keyboard shortcuts for toggling visibility for the different fields/columns.
For example:
f,o . Fields/Columns: 'f' add or remove; 'o' change display order
F or O . Select sort field
<,> . Move sort field: '<' next col left; '>' next col right
You can use the key f while in top
to get to a secondary screen where you can specify which columns should be toggled visible or not:
For example:
Current Fields: ANOPQRSTUVbcdefgjlmyzWHIKX for window 3:Mem
Toggle fields via field letter, type any other key to return
* A: PID = Process Id * W: S = Process Status
* N: %MEM = Memory usage (RES) * H: PR = Priority
* O: VIRT = Virtual Image (kb) * I: NI = Nice value
* P: SWAP = Swapped size (kb) * K: %CPU = CPU usage
* Q: RES = Resident size (kb) * X: COMMAND = Command name/line
* R: CODE = Code size (kb)
...
There are more, these are just a sample. When you're done toggling the columns the way you want, use the Esc to get out of the selection screen.
Saving configuration
You can use the Shift+W to save your changes so they're the defaults:
W Write configuration file
The file is stored here, $HOME/.toprc
, and looks like this:
$ more .toprc
RCfile for "top with windows" # shameless braggin'
Id:a, Mode_altscr=0, Mode_irixps=1, Delay_time=1.000, Curwin=2
Def fieldscur=AEHIoqTWKNMBcdfgjpLrsuvyzX
winflags=129016, sortindx=19, maxtasks=0
summclr=2, msgsclr=5, headclr=7, taskclr=7
Job fieldscur=ABcefgjlrstuvyzMKNHIWOPQDX
winflags=63416, sortindx=13, maxtasks=0
summclr=6, msgsclr=6, headclr=7, taskclr=6
Mem fieldscur=ANOPQRSTUVbcdefgjlmyzWHIKX
winflags=65464, sortindx=13, maxtasks=0
summclr=5, msgsclr=5, headclr=4, taskclr=5
Usr fieldscur=ABDECGfhijlopqrstuvyzMKNWX
winflags=65464, sortindx=12, maxtasks=0
summclr=3, msgsclr=3, headclr=2, taskclr=7
See section 5 of the man page for more details, "5. FILES".
Best Answer
From inside
top
you can try the following:You might also try:
This will give the top 5 processes by memory usage.