I. Check the memory usage
(1) Method 1: Use the free command
This will display the system’s physical memory and swap space usage in a human-readable format.
free Unit K
free -m units of M
free -h unit G
Parameter description
total Total physical memory
used Used memory
free Unused memory
shared Multi-process shared memory
buff/cache Read and write cache memory
available Physical memory available to the application
(2) TOP instruction
The top command is used to monitor the system status of linux, such as cpu and memory usage.
Enter the top command
Press q to exit
By x, the highlighted sorting sequence should be %CPU by default, sorted by CPU usage.
Press shift+> ,to toggle highlighting, you can see the highlighted part to %MEM, sorted by memory usage.
You can also type top and press the “M” key to sort the processes by memory usage to see how much memory each process is using.
(3) View memory before X
Use the following command to view the first 10, and modify the number 10 to view the first X
ps aux | head -1;ps aux |grep -v PID |sort -rn -k +4 | head -10
Or, the number needs an extra +1
ps aux --sort -rss | head -n 11
Second, check the cpu occupancy
View Top 10
ps aux | head -1;ps aux |grep -v PID |sort -rn -k +3 | head -10
Or the following command, the number needs an extra +1
ps aux --sort -pcpu | head -n 11