linux View memory ranking and calculate

Linux command:

ps -aux | sort -k6nr | head -n 100 | awk '{sum+=$6} END {print sum}'

Explanation: Use ps to list the processes, and use sort to sort, -k specifies the sort position, here is the 6th field, nr is sorted in reverse order by numerical value,

The following head is to calculate 100, and finally use awk to process, add the values ​​of the sixth column, and finally output uniformly to get the memory usage of the first 100 programs

Commonly used is free

free -m
             total       used       free     shared    buffers     cached
Mem:          7970       7803        167          0         28       2194
-/+ buffers/cache:       5580       2390
Swap:          511        487         24

Explanation: free is a command for statistical viewing of memory. The -m parameter is the conversion bit in M.

The above fields represent:

        total: total physical memory used: used physical memory (usually refers to the memory used by the program) shared: (each program shares memory)        

        buffer: only cache, mainly for directories cached: system cache, related to the number of open files, mainly used to improve file read and write speed

        Note: The used memory includes cached, which means that the actual memory used by the program is used - cached. When needed, cached will be automatically released and become available.

More detailed memory usage, linux command:

$cat /proc/meminfo
MemTotal: 8162240 kB
MemFree:          169352 kB
MemAvailable:    2489860 kB
Buffers:           31932 kB
Cached:          2235540 kB
SwapCached:         3516 kB
Active:          5588576 kB
Inactive:        2106312 kB
Active(anon):    5401856 kB
Inactive(anon):    25620 kB
Active(file):     186720 kB
Inactive(file):  2080692 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:        524284 kB
SwapFree:          25572 kB
Dirty:               296 kB
Writeback:             0 kB
AnonPages: 5424008 KB
Mapped:            39836 kB
Shmem:                16 kB
Slab:             187364 kB
SReclaimable:     155748 kB
SUnreclaim:        31616 kB
KernelStack:        8352 kB
PageTables:        27088 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     4605404 kB
Committed_AS:    7188828 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk: 0 kB
DirectMap4k:       16248 kB
DirectMap2M:     3129344 kB
DirectMap1G:     7340032 kB

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325873766&siteId=291194637