13、 Linux commands free, top

Time:2021-11-30

Free: the command displays the system memory usage, including physical memory, swap memory, and kernel buffer memory.

Syntax format: free [options]

  

 

Output content:
MemLine (second line) is the memory usage.
SwapLine (third line) is the usage of swap space.
totalThe column shows the total available physical memory and swap space size of the system.
usedColumns show the physical memory and swap space that has been used.
freeThe column shows how much physical memory and swap space are available.
sharedColumn displays the amount of physical memory used by the share.
buff/cacheThe column shows the size of physical memory used by buffer and cache.
availableColumn shows the amount of physical memory that can also be used by the application.

 

 

Options:

-b   Displays memory usage in bytes.

-k   Displays memory usage in kilobytes.

-m   Displays memory usage in megabytes.

-g     Displays memory usage in gigabytes.

-o   Buffer reconciliation columns are not displayed.

-s   Continuously observe the memory usage.

-t   Displays the memory sum column.

-V   Displays version information.

 

 

Top: the command is used to monitor the system status of Linux. Shijingk monitors the system processor status in real time. It can display the resource occupation status of each process in the system. It is a common performance analysis tool, which can display the resource occupation of each process in the system in real time.

 

 

 

The first line, the task queue information, is the same as the execution result of the uptime command

System time: 07:27:05

Running time: up 1:57 min,

Current login user:   3 user

Load balancing (uptime)   load average: 0.00, 0.00, 0.00

The three numbers after average are the load conditions of 1 minute, 5 minutes and 15 minutes respectively.

Load average data is the number of active processes checked every 5 seconds, and then calculated according to a specific algorithm. If this number is divided by the number of logical CPUs, when the result is higher than 5, it indicates that the system is overloaded

The second line, tasks – tasks (processes)

Total process: 150 total, running: 1 running, sleeping: 149 sleeping, stopping: 0 stopped, zombie process: 0 zombie

The third line is CPU status information

0.0% us [user space] – percentage of CPU occupied by user space.

0.3%sy [sysctl] – percentage of CPU occupied by kernel space.

0.0% Ni [] – percentage of CPU occupied by processes with changed priority

99.7% ID [idolt] – percentage of idle CPU

0.0% wa [wait] – percentage of CPU occupied by IO waiting

0.0%hi [hardware IRQ] – percentage of CPU occupied by hard interrupt

0.0% Si [software interrupts] – percentage of CPU occupied by soft interrupts

Line 4, memory status

1003020k total,    234464k used,    777824k free,     24084k buffers

The fifth line, swap, exchanges partition information

2031612k total,       536k used,   2031076k free,    505864k cached [total buffered swap area]

 

Sixth line, blank line

The seventh line is as follows: status monitoring of each process (task)

PID – process ID
User – process owner
PR – process priority
Ni – nice value. Negative values indicate high priority and positive values indicate low priority
Virt – total amount of virtual memory used by the process, in KB. VIRT=SWAP+RES
Res – the size of physical memory used by the process and not swapped out, in KB. RES=CODE+DATA
SHR – shared memory size, in KB
S – process status. D = non interruptible sleep state r = running s = sleep t = tracking / stopping z = zombie process
%CPU – percentage of CPU time consumed since the last update
%Mem – percentage of physical memory used by the process
Time + – total CPU time used by the process, unit: 1 / 100 second
Command – process name (command name / command line)

 

Virt: virtual memory usage
1. The “required” virtual memory size of the process, including the library, code, data, etc. used by the process
2. If a process requests 100 m of memory but actually uses only 10 m, it will increase by 100 m instead of the actual usage

Res: resident memory usage
1. The amount of memory currently used by the process, excluding swap out
2. Share containing other processes
3. If you apply for 100m of memory and actually use 10m, it will only increase by 10m, which is opposite to virt
4. As for the memory occupied by the library, it only counts the memory occupied by the loaded library files

SHR: shared memory
1. In addition to the shared memory of its own process, it also includes the shared memory of other processes
2. Although the process uses only a few shared library functions, it contains the size of the entire shared library
3. The formula for calculating the physical memory occupied by a process: res – SHR
4. After swap out, it will come down

DATA
1. Memory occupied by data. If top is not displayed, press f to display it.
2. The real data space required by the program is really used in operation.

During top operation, the display mode of the process can be controlled through the internal command of top. The internal commands are as follows:
S – change the screen update frequency
L – turn off or on the representation of the top information in the first line of the first part
T – close or open the representation of tasks in the second line and CPUs in the third line of the first part
M – turn off or on the representation of MEM in the fourth line and swap in the fifth line of the first part
N – represents the process list in the order of PID size
P – lists processes in order of CPU usage
M – sort the process list in order of memory usage
H – display help
N – sets the number of processes displayed in the process list
Q – exit top
S – change the screen update cycle

 

Top usage

Use format:

top [-] [d] [p] [q] [c] [C] [S] [s] [n]

Parameter Description:

d: Specify the time interval between screen information refreshes. Of course, users can use the s interactive command to change it.

p: Monitor the status of only one process by specifying the monitoring process ID.

q: This option will enable top to refresh without any delay. If the caller has superuser privileges, top will run at the highest possible priority.

S: Specifies the cumulative mode.

s: Make the top command run in safe mode. This removes the potential danger posed by interactive commands.

i: Make top not show any idle or dead processes.

c: Displays the entire command line, not just the command name.