使用脚本获得 消耗Linux操作系统内存的前10个用户

[root@rhel63single ~]# uname -r
2.6.32-279.el6.x86_64
[root@rhel63single ~]# uname -a
Linux rhel63single 2.6.32-279.el6.x86_64 #1 SMP Wed Jun 13 18:24:36 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux
[root@rhel63single ~]# ps -eo user,pcpu,pmem | tail -n +2 | awk '{num[$1]++; cpu[$1] += $2; mem[$1] += $3} END{printf("NPROC\tUSER\tCPU\tMEM\n"); for (user in cpu) printf("%d\t%s\t%.2f\t%.2f\n",num[user], user, cpu[user], mem[user]) }'
NPROC USER CPU MEM
13 gdm 0.10 3.50
1 rpc 0.00 0.00
1 dbus 0.00 0.00
22 grid 8.60 28.90
2 68 0.00 0.20
1 rtkit 0.00 0.00
2 postfix 0.00 0.20
2 avahi 0.00 0.00
1 rpcuser 0.00 0.00
158 root 0.10 2.50

 

对结果的解读:

gird用户有22个进程,这22个进程一共消耗了28.9%的物理内存。