例3
需求:统计你的linux下运行的所有进程占用内存的和?
使用的命令:awk;ps aux
#!/bin/bash
RSS=`ps aux | grep -v 'RSS' | awk '{print $6}'`
sum=0
for i in $RSS
do
sum=$[ $sum+$i ]
done
echo "所有进程占用内存和为:"$sum
本篇没什么知识点,只需要会使用ps aux即可,附上ps aux部分内容
[root@proxy124 shell3]# ps aux |head
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 21436 1252 ? Ss Apr12 0:03 /sbin/init
root 2 0.0 0.0 0 0 ? S Apr12 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S Apr12 0:00 [migration/0]
root 4 0.0 0.0 0 0 ? S Apr12 0:59 [ksoftirqd/0]
root 5 0.0 0.0 0 0 ? S Apr12 0:00 [migration/0]
root 6 0.0 0.0 0 0 ? S Apr12 0:28 [watchdog/0]
root 7 0.0 0.0 0 0 ? S Apr12 143:23 [events/0]
root 8 0.0 0.0 0 0 ? S Apr12 0:00 [cgroup]
root 9 0.0 0.0 0 0 ? S Apr12 0:00 [khelper]