shell习题--统计内存的使用

shell – 统计内存的使用

需求:

写一个脚本计算一下linux系统所有进程占用内存大小的和。(提示,使用ps或者top命令)

#! /bin/bash

#定义一个参数,是和
sum=0

#通过ps aux 命令和AWK正则,经过for循环,依次赋值给mem
for mem in `ps aux |awk ‘{print $6}’ |grep -v ‘RSS’ `

do
#做一个相加
sum=$[$sum+$mem]

done

#输出mem的总量
echo “The total memory is $sum””k”

猜你喜欢

转载自blog.csdn.net/aoli_shuai/article/details/79628665