Processor usage here we need to extract four pieces of data from/proc/stat: user mode, nice mode, and system mode) and idle processor time (idle ). They are located in the first line of the/proc/stat file. The CPU usage is calculated using the following formula. CPU Usage = 100 * (user + nice + system)/(user + nice + system + idle)
CPU usage
Here, we need to extract four pieces of data from/proc/stat: user mode, nice mode, and system mode) and idle processor time (idle ). They are located in the first line of the/proc/stat file. The CPU usage is calculated using the following formula.
CPU Usage = 100 * (user + nice + system)/(user + nice + system + idle)
Idle memory = free + buffers + cached = total-used
Available memory = free memory + cached memory + buffers memory
Real Memory Usage = available memory/total memory (note that the available memory here is calculated by the formula above. In fact, this calculation result is already available in the free command Echo, that is, the third row of the Echo result "-/+ buffers/cached". The second value of this row is the memory after buffers and cached are added, that is, the available memory calculated by the above formula ).
In Linux, you can enter the free command to obtain the memory usage of the current system.
# Busybox free
Total used free shared buffers
Mem: 55636 52808 2828 0 3132
Swap: 0 0 0
Total: 55636 52808 2828
When I typed the above Command with joy, I received a burst of cold sweat, 2828 KB. my system only has more than 2 MB of memory. Can the system still run, is there a command error !!!
Let's take a look at what the results look like in a Linux system on a PC.
# Free
Total used free shared buffers cached
Mem: 4091524 4021016 70508 0 7656 1824312
-/+ Buffers/cache: 2189048 1902476
Swap: 4088532 2891732 1196800
Here I will explain several key concepts first.
Buffers: it is mainly used to buffer block devices in Linux.
Cached: used to buffer the files we open.
Memory is a very valuable resource in the system. Linux uses memory to cache some files if the memory is sufficient and you do not need to use it for whitelist. This speeds up the process; when the memory is insufficient, the memory will be recycled for use by the program.
Therefore, the real available memory is free + buffers + cached = 70508 + 7656 + 1824312 = 1902476.