The top
command provides a dynamic real-time view of the running system, displaying system summary information as well as a list of processes or threads currently managed by the kernel. The types of system summary information displayed and the type, order, and size of information displayed for tasks are all user-configurable.
top -hv | -bcHisS -d delay -n limit -u|U user | -p pid -w [cols]
-h
: Output help information.-v
: Output version information.-b
: Starttop
in batch mode, useful for sending output fromtop
to other programs or files,top
will not accept input and run until you set an iteration limit or terminate using the-n
command line option.-c
: Start with last rememberedc
state, iftop
shows command lines, the field will now show program names, and vice versa.-d interval
: Specify the delay between screen updates, overriding the corresponding value in the personal configuration file or the default value at startup, thed
ors
interactive command can also be used after startup to change the delay.-H
: Instructtop
to display individual threads, if this command line option is not present, it shows the sum of all threads in each process, theH
interactive command can be used after startup to change this.-i
: Idle process switch, start with last rememberedi
state, when this switch is off, tasks that have not used any CPU since the last update will not be shown.-n limit
: Specify the maximum number of iterations or framestop
should produce before ending.-o
: Specifies the name of the field to sort tasks by, independent of what is reflected in the configuration file, you can prefix the field name with+
or-
to override the sort direction, a leading+
will force a high-to-low sort and-
will ensure a low-to-high sort, primarily used for supporting automated script-driven batch mode operations.-O
: This option is a help form of the-o
option, it will maketop
print each available field name on a separate line and then exit.-p pid
: Monitor only processes with the specified process ID, this option can be given up to20
times, it can also take a comma-separated list containing up to20
PIDs, allowing both methods to be mixed, apid
value of zero will be considered as the process id of thetop
program when running, this is just a command line option, if you want to return to normal operation, there is no need to exit and restarttop
, just issue either of the interactive commands=
,u
, orU
, thep
,u
, andU
command line options are mutually exclusive.-s
: Safe mode operation, forcibly starttop
in safe mode even forroot
, better control of this mode can be achieved through system configuration files.-S
: Cumulative time switch, start with last rememberedS
state, when cumulative time mode is on, each process will list the CPU time it and its child processes have used.-u user-id-or-name, -U user-id-or-name
: Display only processes that match the given user ID or username, the-u
option matches valid users while the-U
option matches any userreal
,effective
,saved
, orfilesystem
, prefixing a user ID or name with an exclamation mark!
tellstop
to display processes that do not match the provided user, thep
,u
, andU
command line options are mutually exclusive.-w number
: In batch mode, if there are no parameters,top
will useCOLUMNS=
andLINES=
environment variables (if set) to format the output, otherwise the width will be fixed at a maximum of512
columns, with a parameter, the output width can be reduced or increased (up to512
lines), but the number of lines is considered to be unlimited, in normal display mode, if there are no parameters,top
will attempt to format the output usingCOLUMNS=
andLINES=
environment variables (if set), the output width can only be reduced with a parameter, not increased, whether using environment variables or a parameter with-w
, it cannot exceed the actual terminal dimensions when not in batch mode, note that if this command line option is not used, the output width is always based on the dimensions of the terminal in whichtop
is invoked, whether in batch mode or not.
The following default value operations assume no related configuration file, that is, no user customization, plus items are overrideable through the command line.
^Z
: Suspend.fg
: Resume a suspended command.<Left>
: Force screen redraw.A
: Alternate display, default full screen display.d
:*
Delay time, default3s
.H
:*
Thread mode, default off.I
:Irix
mode, default on.p
:*
MonitoringPID
, default show all processes.1
: View the logical count of CPU on the server.M
: Sort by resident memory size.P
: Sort by CPU usage percentage.T
: Sort by time/cumulative time.c
: Switch display of command name and full command line.t
: Switch display of process and CPU information.m
: Switch display of memory information.l
: Switch display of average load and uptime information.o
: Change the order of displayed items.f
: Add or remove column items from the current display.S
: Switch to cumulative mode.s
: Change the delay time between two refreshes, the system will prompt the user to enter the new time, in seconds, if it has a decimal, it will be converted to milliseconds.q
: Exit thetop
command.i
: Ignore idle and zombie processes.k
: Terminate a process.
total
: Total number of processes.running
: Number of processes currently running.sleeping
: Number of processes in sleep mode.stopped
: Number of stopped processes.zombie
: Number of zombie processes.
us
: Percentage of CPU usage in user space.sy
: Percentage of CPU usage in kernel space.ni
: Percentage of CPU usage by processes with modified priority in user space.id
: Percentage of idle CPU.wa
: Percentage of CPU time spent waiting for input/output.hi
: Percentage of CPU time spent on hardware interrupts.si
: Percentage of CPU time spent on software interrupts.st:
Percentage of CPU time taken by virtual machines.
You can use the f
interactive command to customize the position and visibility of the columns.
%CPU
:CPU Usage
, the percentage of CPU time used by tasks since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if a process is multi-threaded andtop
is not in thread-mode, it may report a value greater than100%
. You can use theH
interactive command to switch to thread-mode. Similarly, in a multi-processor environment, ifIrixmode
is off,top
will run inSolarismode
, where the task'sCPU
usage is divided by the total number of CPUs. You can use theI
interactive command to switchIrix/Solaris
mode.%MEM
:Memory Usage (RES)
, the amount of physical memory the task is currently using.CGROUPS
:Control Groups
, the name of the control group to which the process belongs. Control groups are used to allocate resources (CPU, memory, network bandwidth, etc.) among predefined process groups. An important aspect ofcgroups
is that it is not of a fixed width like most columns. When displayed, it will consume all remaining screen width (up to 512 characters). Despite this, this variable-width field may still be truncated.CODE
:Code Size (KiB)
, the amount of physical memory in KiB used for executable code, also known as the Text Resident Set size orTRS
.COMMAND
:Command Name or Command Line
, displays the command line used to start the task or the name of the associated program. You can usec
to switch between the command line and the name. When displaying the command line, processes without a command line (such as kernel threads) will only display the program name. This field may also be affected by the view display mode. Similar toCGROUPS
, it is not of a fixed width, when displayed, it will consume all remaining screen width (up to 512 characters) and may be truncated when displaying command lines.DATA
:Data + Stack Size (KiB)
, the amount of physical memory in KiB used for data and stack beyond the executable code, also known as the Data Resident Set size orDRS
.ENVIRON
:Environment variables
, displays all the environment variables seen by each process, if any. They are shown in the original native order, not the sorted order seen with the non-POSIXset
. Similar toCGROUPS
, it's not a fixed width field. When displayed, it will consume all remaining screen width (up to 512 characters) and may be truncated.Flags
:Task Flags
, indicates the current scheduling flags of the task, represented in hexadecimal and does not include zeroes. These flags are formally defined in<linux/sched.h>
.GID
:Group Id
, the effective groupID
.GROUP
:Group Name
, the effective group name.NI
:Nice Value
, a negativenice
value means a higher priority, while a positivenice
value means a lower priority. A value of zero in this field means the priority will not be adjusted when determining the task's scheduling capability.P
:Last used CPU (SMP)
, indicates the number of the last used processor. In a true SMP environment, this may change frequently because the kernel deliberately uses weak affinity. Additionally, the behavior of runningtop
may break this weak affinity and cause more processes to change CPUs more frequently due to extra demands on the CPU time.PGRP
:Process Group Id
, every process is a member of a unique process group used for signal allocation and arbitrated for terminal input and output. When a process is created (forked
), it becomes a member of its parent process group. By convention, its value is equal to the processID
of the first member of the process group (known as the process group leader).PID
:Process Id
, the unique processID
of the task. It wraps around periodically, but never restarts at zero. In the kernel, it's a schedulable entity defined bytask_struct
. This value is also used as thePID
, sessionID
for the session leader, thread groupID
for the thread group leader, and theTTY
process groupID
for the process group leader.PPID
:Parent Process Id
, the processID
of the parent process of the task (pid
).PR
:Priority
, the scheduling priority of the task. If you seert
in this field, it means the task is running at a real-time scheduling priority. Real-time priorities, underlinux
, have traditionally been misleading because it traces back to the fact that the operability of the system is not preemptible. The2.6
kernel can be pre-emptible in most areas, but not all.RES
:Resident Memory Size (KiB)
, the amount of non-swapped physical memory used by the task.RUID
:Real User Id
, the real userID
.RUSER
:Real User Name
, the real user name.S
:Process Status
, the status of the task which can be:D
uninterruptible sleep,R
running,S
sleeping,T
traced or stopped,Z
zombie. Tasks shown as running should be considered ready to run — their task structures are only in theLinux
run queue. According totop
, a significant, although unknowable, amount of work has likely been done to the task structures in this case because oftop's
latency interval and nice value, you will usually see many tasks in this state.SHR
:Shared Memory Size (KiB)
, the amount of shared memory the task can use. Typically, not all of the memory is actually moved to disk. It just means that the task may need to load more pages of memory than are currently resident.SID
:Session Id
, a session is a set of process groups, typically established by a loginshell
. Newlyforked
processes join the session of their creator. By convention, its value is equal to thePID
of the session's first member, known as the session leader, normally a loginshell
.SUID
:Saved User Id
, the saved userID
.SUPGIDS
:Supplementary Group IDs
, any supplementary groups established or inherited from the task's parent. They are displayed as a comma separated list. Similar toCGROUPS
, it's not a fixed width field. When displayed, it will consume all remaining screen width (up to 512 characters) and may be truncated.SUPGRPS
:Supplementary Group Names
, any supplementary groups established or inherited from the task's parent. They are displayed as a comma separated list. Similar toCGROUPS
, it's not a fixed width field. When displayed, it will consume all remaining screen width (up to 512 characters) and may be truncated.SUSER
:Saved User Name
, the saved user name.SWAP
:Swapped Size (KiB)
, the non-resident part of the task's address space.TGID
:Thread Group Id
, the thread groupID
to which the task belongs. It's thePID
of the thread group leader and represents those tasks that share themm_struct
in kernel terms.TIME
:CPU Time
, the total CPU time the task has used since it started. When the accumulation mode is on, each process will list the CPU time used by itself and its children. UseS
to toggle accumulation mode. This is both a command line option and an interactive command. For more information on this mode, see theS
interactive command.TIME+
:CPU Time, hundredths
, the same asTime
, but reflects more granularity in hundredths of a second.TPGID
:Tty Process Group Id
, the process groupID
of the foreground process connected to thetty
. If the process is not connected to a terminal, it is-1
. By convention, this value is equal to the processID
of the process group leader.TTY
:Controlling Tty
, the name of the controlling terminal. This is typically the device of the process that started the terminal (serial port,pty
, etc.) and is used for input or output. However, tasks don't need to be associated with a terminal. In such cases, you will see a?
displayed.UID
:User Id
, the effective userID
of the task owner.USED
:Memory in Use (KiB)
, this field represents the amount of non-swapped physical memory (RES
) used by the task plus the non-resident part of its address space (SWAP
).USER
:Username
, the effective username of the task owner.VIRT
:Virtual Memory Size (KiB)
, the total amount of virtual memory the task is using. It includes all code, data and shared libraries as well as pages that have been swapped out and pages that have not been used but have been mapped.WCHAN
:Sleeping in Function
, depending on the kernel compile options, this field will show the name or address of the kernel function the task is currently sleeping in. A running task will display a dash-
in this column. By showing this field,top
can increase its own working set by over 700 kb, depending on the kernel version. If this happens, the only way you can get rid of this added load is to stop and restarttop
.nDRT
:Dirty Pages Count
, the number of pages modified since being written to secondary storage.Dirty pages
need to be written out to secondary storage before the corresponding physical memory location can be used for another virtual page.nMaj
:Major Page Fault Count
, the number of major page faults the task has had. A major page fault occurs when a process tries to read or write a page that is currently not in memory, which involves bringing such a page into memory.nMin
:Minor Page Fault Count
, the number of minor page faults the task has had. A minor page fault occurs when a process tries to read or write a page that is currently not in memory, without any involved access to the disk.nTH
:Number of Threads
, the number of threads associated with the process.nsIPC
:IPC namespace
, theInode
for the namespace isolating Inter-Process Communication (IPC
) resources such asSystemVIPC
objects andPOSIX
message queues.nsMNT
:MNT namespace
, theInode
for the namespace isolating the mount points, providing different views of the filesystem hierarchy.nsNET
:NET namespace
, theInode
for the namespace isolating network devices,IP
addresses,IP
routes, port numbers, etc.nsPID
:PID namespace
, theInode
for the namespace isolating processID
numbers, meaning they do not have to be unique in this namespace, so each namespace can have its owninit
(PID#1
) to manage various initialization tasks and obtain isolated child processes.nsUSER
:USER namespace
, theInode
for the namespace isolating user and groupID
numbers. This means a process can have a regular unprivileged userID
outside the user namespace and a userID
of 0 with full root capabilities inside the namespace.nsUTS
:UTS namespace
, theInode
for the namespace isolating the hostname andNIS
domain name.UTS
stands forUNIX
Time-sharing System.vMj
:Major Page Fault Count Delta
, the number of major page faults that has occurred since the last update.vMn
:Minor Page Fault Count Delta
, the number of minor page faults that has occurred since the last update.
Display process information.
top
Show complete command.
top -c
Display program information in batch mode.
top -b
Display program information in cumulative mode.
top -S
Set the number of refreshes to 2
, terminate after updating twice.
top -n 2
Set the refresh time to 3
seconds.
top -d 3
Display specified process information, such as CPU
, memory usage, etc.
top -p 131
Unable to send commands to the process interactively.
top -s
https://github.com/WindrunnerMax/EveryDay
https://www.computerhope.com/unix/top.htm
https://www.commandlinux.com/man-page/man1/top.1.html
https://www.geeksforgeeks.org/top-command-in-linux-with-examples/