Memory - ps view the memory consumption of the current process

Under linux, the current memory consumption is usually viewed through the free command

E.g:

admin@k5:/data/user/3798c # free
             total         used         free       shared      buffers
Mem:       1827576      1215184       612392         1584        11732
-/+ buffers:            1203452       624124
Swap:            0            0            0

 

But when you want to know which processes are using the memory used? And which process is the most used?

You can use the ps command, plus the corresponding filtering to achieve.

First explain the meaning of each line of the corresponding ps:

admin@k5:/data/user/3798c # ps -aux | head -1
USER     PID       PPID      VSIZE      RSS         WCHAN    PC        NAME
所有者    进程ID    父进程ID    虚拟内存    物理内存    /        pc指针    进程名

Use the ps command to view the top processes that currently consume the most physical memory:

admin@k5:/data/user/3798c # ps aux|head -1;ps|grep -v PID|sort -rn -k 5|head                                                                                                                            
USER     PID   PPID  VSIZE  RSS     WCHAN    PC        NAME
root      1815  1     209020 759012 ffffffff b6de77cc S /system/bin/bootanimation
system    1998  1541  1063884 97780 ffffffff b6dcab60 S system_server
u0_a10    2160  1541  986848 89392 ffffffff b6dcab60 S com.android.systemui
u0_a45    2366  1541  986084 77296 ffffffff b6dcab60 S com.android.launcher
root      1541  1     940236 75516 ffffffff b6dcb0c0 S zygote
radio     2333  1541  964964 60672 ffffffff b6dcab60 S com.android.phone
u0_a22    2747  1541  968344 54216 ffffffff b6dcab60 S com.android.email
u0_a4     2124  1541  956236 50644 ffffffff b6dcab60 S android.process.media
system    2670  1541  970640 46924 ffffffff b6dcab60 S com.android.settings
u0_a19    2724  1541  954600 46408 ffffffff b6dcab60 S com.android.deskclock

The first sentence is mainly to get the title (USER PID PPID VSIZE RSS WCHAN PC NAME).
The next grep -v PID is to remove the title obtained by the ps aux command, that is, grep does not contain the three-letter combination of PID, and then sort the results by sort.
sort -rn -k 5 In this command, the r of -rn indicates that the results are sorted in reverse order, n is sorted by numerical value, and -k 5 is to sort the contents of the fifth column (the fifth line indicates the physical Memory), and then use the head command to get the default first 10 rows of data. (Where | means pipeline operation)

Guess you like

Origin blog.csdn.net/Ivan804638781/article/details/97130332