dynamically show processes, memory usage
Many implementations exist and all have different options, this is for ??
| event counting :
delta. (relative to previous sample),
non-event (default). CPU usage since previous sample.
|logging mode in raw form.
| non-logging i.e. interactive
| sort on key in descending order. |
+ prefixed ascending,
|secondary sort key |
cpu CPU usage.
pid Process ID (default).
prt Number of Mach ports.
reg Number of memory regions.
rprvt Resident private address space size.
rshrd Resident shared address space size.
rsize Resident memory size.
th Number of threads.
time Execution time.
uid User ID.
vprvt Private address space size.
vsize Total memory size.
| recursively traverse and report the memory object map for each process (default).
|not recursive . This substantially reduces the amount of processor time top consumes.
|speed of updates
| Translate uid numbers to usernames.
| Do not " "
| Only display processes owned by|
username or uid
| omitt frameworks(i.e. shared libraries) substantially reduces processor time top consumes.
|include shared libraries(default).
Command line options are processed from left to right.
If conflicting options are specified, later specifications overrides .
viable to create a shell alias for top with preferred defaults , then override those preferred defaults as desired on the command line.
The first several lines show the global state.
|Percentage of processor usage, broken into user, system, and idle components.
|reads and writes.
|over 1, 5, and 15 minutes.
|Number and total size of memory regions, and total size of memory regions broken into private (broken into non-library and library) and shared components.
|wired, active, inactive, used, and free components.
|Total number of processes and number of processes in each process state.
|Number of shared libraries, resident sizes of code and data segments, and link editor memory usage.
|in accumulative event counting mode, the time since top started is printed in parentheses
|Total virtual memory, virtual memory consumed by shared libraries, and number of pageins and pageouts.
| faults causing a page to be copied.
| context switches.
| Mach messages received.
| Mach sent.
| Mach ports.
| Resident private memory size.
| Resident shared
| Total resident , including shared pages.
| BSD system calls
| Number of threads.
| Absolute processor time consumed.
| Private address space size.
| Total address space allocated, including shared pages.
When interactive, control the output as well as sendinf signals to processes.
Each command is one character, followed by up to 2 arguments.
Commands that take arguments prompt for them the default value is shown in square brackets.
The default value can be selected by leaving the input field blank and pressing enter.
^G escapes the interactive argument prompt and is the same as leaving the input field blank and pressing enter.
other Keypresses cause a sample update.
| ^L || Redraw the screen.
| n|| Only display processes. 0 =all
| okey ||sort on key in descending order. |
| Oskey skey ||secondary key
|Number of Mach ports.
|Number of memory regions.
|Resident private address space size.
|Resident memory size.
|Number of threads.
|Total memory size.
| f || frameworks
| r ||recursive (traversal)of the memory object map for each process.
|t ||translation of uid numbers to usernames.
| U ||Only display processes owned by . Either the username or uid number can be specified. To display all processes, press enter without entering a username or uid number.
| w || wide/narrow delta
| x|| deprecated/normal
| S signal pid || a number or as a name (for example, |
Default TERM. Each time a signal is successfully sent, the default signal is updated to be that signal.
|-a ||use -ca.
|-d ||use -cd.
|-e ||use -ce.
|-k ||memory object reporting for process 0 (kernel_task), default.
| -u ||use -ocpu -Otime.
Translate uid numbers to usernames and run in logging mode, taking 10 samples at 2 second intervals.
top -ocpu -O+rsize -s 5 -n 20
Sort the processes according to CPU usage (descending) and
sOresident memory size (ascending),
update every 5 seconds
and limit to 20 processes.
top -ce # Run top in event counter mode.
top -tl 10
htop, kill, vm_stat, signal
from BSD Apple darwin 7.9.0
Each version of *nix has their own implementaition of
This document reflects Apple Mac OS X El Captian.
top [-a | -d | -e | -c mode]
[-F | -f]
[-o key] [-O ]
[-R | -r]
Periodically displays a list of system processes. The default sorting key is
Options are processed from left to right. For repeated options: later specifications override earlier ones.
This makes it viable to create a shell
alias for top with preferred defaults then override those preferred defaults as desired on the command line.
| Delta mode. Since previous sample. Default.
|Accumulative mode. Count events, CPU usage and time, since the launch of top.
Disables the memory object map reporting, re-enabled with
-r or the interactive
| Absolute mode. (i.e. since startup)
| Non-event mode (default). Calculate CPU usage since the previous sample.
|Calculate statistics on shared libraries, also known as frameworks (default).
| Do not "
Update framework info every |
samples ; see the PERFORMANCE vs. ACCURACY section below for more details.
logging mode and display samples samples|
Rather than redisplaying, output is periodically output in raw form.
The first sample will have an invalid
%CPU for each process, as it is calculated using the delta between samples.
| Display |
columns in logging mode.
| Only display nprocs processes.
| Order the process display by sorting on |
key in descending order.
- can be prefixed to the key name to specify ascending or descending
-O skey Use skey as a secondary key
user alias: username Username.
time Execution time.
#th threads (total/running).
#wq workqueue total/running.
prt Mach ports.
mem Internal memory (0B zero bytes)
pgrp Process group id
ppid Parent process id
state running | sleeping | stuck
held by the process transitions
from unboosted to boosted
An asterisk indicates
the process was able to send boosts
at some point since the previous update.
cpu_me CPU time charged to me
by other processes.
cpu_others CPU time charged to
other processes by me.
uid User ID.
faults page faults.
cow copy-on-write faults.
msgsent mach messages sent
msgrecv mach messages received
sysbsd BSD syscalls
sysmach Mach syscalls
csw context switches
reg memory regions.
rprvt Resident private address space
vprvt Private address space
kprvt kernel Private
kshrd kernel Shared
pstate Process state.
-o cpu -O time.
|Traverse and report the memory object map for each process (default).
| Do not ""
|Display the global statistics for swap and purgeable memory.
Set the delay between updates to |
delay seconds. Default: 1 second.
| Only display the comma separated statistics.
| Only display |
processid in top.
| Only display processes owned by user.
prio / nice is not displayed! (see
ps -o nice -o pri
The first several lines of show global state.
| Total number of processes and number of processes in each process state.
| Number of threads.
| in logging mode YYYY/MM/DD HH:MM:SS format by default.
overridden with accumulative mode. |
When running in accumulative event counting mode, the Time is in HH:MM:SS since the beginning of the top process.
| Load average over 1, 5, and 15 minutes. i.e. average number of jobs in the run queue.
| Percentage of processor usage, by user, system, and idle components. |
The time period for which these percentages are calculated depends on the event counting mode.
| Resident sizes of code and data segments, and link editor memory usage.
| Number and total size of memory regions, and total size of memory regions by private (by
non-library and library) and shared components.
| Physical memory usage, broken into wired, active, inactive, used, and free components.
| Total virtual memory, virtual memory consumed by shared libraries, and number of pageins and pageouts.
|Number and total size of input and output network packets.
| Number and total size of disk reads and writes.
|Swap usage: total size of swap areas, amount of swap space in use and amount of swap space available.
|Number of pages purged and number of pages currently purgeable.
Below the global state fields, a list of processes is displayed.
pid displays the following for the architecture:
+ for 64-bit native
- for 32-bit native
* for a non-native .
Commands re one character, arguments are prompted for, (default shown in brackets), selected by pressing enter.
? Display the help screen.
^L Redraw the screen.
o key sorting on key A + or - prefix ascending or descending
O skey skey is secondary key
r Toggle traversal and reporting of the memory object map for each process.
S signal pid Send
The default signal starts out as
Each time a signal is successfully sent, the default signal is updated to be that signal.
sdelay between updates
Uuser Only display processes owned by user.
Either the username or uid number
To display all processes, press enter
PERFORMANCE vs. ACCURACY
Calculating detailed memory statistics is resource-intensive. To reduce the cpu usage framework stats
will be updated once every 10 samples. Specifying
-i 1 will result in the most accurate display, at the expense of
N/A - Not Available: Caused by the memory object map reporting being disabled. (default in delta mode)
, but may be enabled via
-r or the interactive
r command after any
Sort the processes according to CPU usage (descending) and resident memory size (ascending), sample and update
the display at 5 second intervals, and limit the display to 20 processes.
top -o cpu -O +rsize -s 5 -n 20
Run top in delta mode.
top -c d
Display only the specified statistics, regardless of any growth of the terminal. If the terminal is too small,
only the statistics that fit will be displayed.
top -stats pid,command,cpu,th,pstate,time