How to see top processes sorted by actual memory usage?

前端 未结 12 994
栀梦
栀梦 2020-12-07 06:53

I have a server with 12G of memory. A fragment of top is shown below:

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                              


        
12条回答
  •  一个人的身影
    2020-12-07 07:21

    How to total up used memory by process name:

    Sometimes even looking at the biggest single processes there is still a lot of used memory unaccounted for. To check if there are a lot of the same smaller processes using the memory you can use a command like the following which uses awk to sum up the total memory used by processes of the same name:

    ps -e -orss=,args= |awk '{print $1 " " $2 }'| awk '{tot[$2]+=$1;count[$2]++} END {for (i in tot) {print tot[i],i,count[i]}}' | sort -n
    

    e.g. output

    9344 docker 1
    9948 nginx: 4
    22500 /usr/sbin/NetworkManager 1
    24704 sleep 69
    26436 /usr/sbin/sshd 15
    34828 -bash 19
    39268 sshd: 10
    58384 /bin/su 28
    59876 /bin/ksh 29
    73408 /usr/bin/python 2
    78176 /usr/bin/dockerd 1
    134396 /bin/sh 84
    5407132 bin/naughty_small_proc 1432
    28061916 /usr/local/jdk/bin/java 7
    

提交回复
热议问题