Linux top command plays a vital role in daily monitoring of server status.
This linux tutorial mainly shares with you how to sort the linux system CPU usage or memory usage when using the linux top command.
top sort by CPU in linux
A leading ‘+’ will force sorting high to low, whereas a ‘-” will ensure a low to high ordering.
# high to low
➜ ~ top -o +%CPU
# low to high
➜ ~ top -o -%CPU
top sort by memory in linux
➜ ~ top -o +%MEM
top sort by pid in linux
➜ ~ top -o +PID
top command supports sorted fields
Descriptions of fields
- PID: Shows task’s unique process id.
- USER: User name of owner of task.
- PR: Stands for priority of the task.
- NI: Represents a Nice Value of task. A Negative nice value implies higher priority, and positive Nice value means lower priority.
- VIRT: Total virtual memory used by the task.
- RES: Resident Memory Size (KiB).
- SHR: Represents the Shared Memory size (kb) used by a task.
- S : Process Status. The status of the task which can be one of:
- D = uninterruptible sleep
- I = idle
- R = running
- S = sleeping
- T = stopped by job control signal
- t = stopped by debugger during trace
- Z = zombie
- %CPU: Represents the CPU usage.
- %MEM: Shows the Memory usage of task.
- TIME+: CPU Time, the same as ‘TIME’, but reflecting more granularity through hundredths of a second.
- COMMAND: Command Name or Command Line.
Best linux commands articles:
Linux common commands tutorial and use examples
Sed command tutorials in linux/unix with examples and use cases
Awk command tutorials in linux/unix with examples and use cases