ps 可以查看进程的内存占用大小,写一个脚本计算一下所有进程所占用内存大小的和。(提示,使用ps aux 列出所有进程,过滤出RSS那列,然后求和){{{密码回复可见}}}
0
p1=`ps aux | awk '{print $6}' | grep -v 'RSS'`
m=0
p2=`echo $p1 | sed 's/\n/ /g'`
for i in `echo $p2`
do
m=$[$m+$i]
done
echo $m
p1=`ps aux | awk '{print $6}' | grep -v 'RSS'`
m=0
p2=`echo $p1 | sed 's/\n/ /g'`
for i in `echo $p2`
do
m=$[$m+$i]
done
echo $m
0
本帖最后由 shajoe 于 2015-9-21 10:21 编辑
ps aux |awk '{(sum=sum+$6)}; END {print sum}'
效果与答案相同, grep -v 'RSS TTY' 匹配这个有什么含义
ps aux |awk '{(sum=sum+$6)}; END {print sum}'
效果与答案相同, grep -v 'RSS TTY' 匹配这个有什么含义
0
本帖最后由 qqq998492 于 2015-9-25 13:41 编辑
#! /bin/bash
ps aux |awk '{print $6}'|grep -v 'RSS'| awk '{(sum+=$1)}; END {print sum}'
#! /bin/bash
ps aux |awk '{print $6}'|grep -v 'RSS'| awk '{(sum+=$1)}; END {print sum}'
0
本帖最后由 J!_yuan 于 2015-11-20 16:36 编辑
sumlog=`ps -aux|awk '{print $6}'|grep '^[1-9]'`
local sum=0
for lines in `echo $sumlog`
do
sum=$[$sum+${lines}]
done
echo $sum
sumlog=`ps -aux|awk '{print $6}'|grep '^[1-9]'`
local sum=0
for lines in `echo $sumlog`
do
sum=$[$sum+${lines}]
done
echo $sum
0
#! /bin/bash
n=`ps aux | awk '{print $6}'|grep -v RSS`
for i in $n
do
sum=$[ $i+$sum ]
done
echo $sum
n=`ps aux | awk '{print $6}'|grep -v RSS`
for i in $n
do
sum=$[ $i+$sum ]
done
echo $sum
0
#!/bin/bash
sum=0
ps aux > /tmp/1.txt ; awk '{print $6}' /tmp/1.txt > /tmp/2.txt ; grep -E '^[0-9]+$' /tmp/2.txt > /tmp/3.txt
for i in `cat /tmp/3.txt`
do
sum=$[ $sum+$i ]
done
echo "你系统所有进程占用内存的大小是$sum KB"
rm -rf /tmp/[123].txt
sum=0
ps aux > /tmp/1.txt ; awk '{print $6}' /tmp/1.txt > /tmp/2.txt ; grep -E '^[0-9]+$' /tmp/2.txt > /tmp/3.txt
for i in `cat /tmp/3.txt`
do
sum=$[ $sum+$i ]
done
echo "你系统所有进程占用内存的大小是$sum KB"
rm -rf /tmp/[123].txt
0
#!/bin/bash
list=`ps aux |awk '{print $6}' |grep '[0-9]'`
sum=0
for i in $list
do
sum=`expr $sum + $i`
done
echo "sum is "$sum
exit
list=`ps aux |awk '{print $6}' |grep '[0-9]'`
sum=0
for i in $list
do
sum=`expr $sum + $i`
done
echo "sum is "$sum
exit
0
#!/bin/bash
##sum of ps aux rss col
##write by 2016-01-08
sum=0
row=$[`ps aux|wc -l`+2]
for ((i=2;i<"$row";i++));do
a=`ps aux|sed -n "$i"p|awk '{print $6}'`
sum=$[$sum+$a]
done
echo "now all of process used $sum KB MEM"
##sum of ps aux rss col
##write by 2016-01-08
sum=0
row=$[`ps aux|wc -l`+2]
for ((i=2;i<"$row";i++));do
a=`ps aux|sed -n "$i"p|awk '{print $6}'`
sum=$[$sum+$a]
done
echo "now all of process used $sum KB MEM"
0
#! /bin/bash sum=0 for i in `ps aux | awk '{print $6}'|grep -v '/RSS/'`; do sum=$[$sum+$i] done echo $sum
0
#!/bin/bash
ps aux |grep -v RSS |awk -F ' ' {'print $6'} > aux.txt
for i in `cat aux.txt`
do
echo $i
sum=$[$sum+$i]
done
echo $sum
ps aux |grep -v RSS |awk -F ' ' {'print $6'} > aux.txt
for i in `cat aux.txt`
do
echo $i
sum=$[$sum+$i]
done
echo $sum
0
#!/bin/bash
n=`ps aux|awk '{print $6}'|sed 's/RSS/0/g'|wc -l`
ps aux|awk '{print $6}'|sed 's/RSS/0/g'>1.txt
a=0
for i in `seq 1 $n`
do
num=`head -$i ./1.txt|tail -1`
let a=a+num
done
echo $a
n=`ps aux|awk '{print $6}'|sed 's/RSS/0/g'|wc -l`
ps aux|awk '{print $6}'|sed 's/RSS/0/g'>1.txt
a=0
for i in `seq 1 $n`
do
num=`head -$i ./1.txt|tail -1`
let a=a+num
done
echo $a
0
- [root@aliyun-63 303]# ps aux | awk 'NR>=2 {print $6}' | awk '{sum+=$1}END{print sum}'
- 259216
- [root@aliyun-63 303]# free -m
- total used free shared buffers cached
- Mem: 994 823 170 0 204 411
- -/+ buffers/cache: 207 786
- Swap: 0 0 0
- [root@aliyun-63 303]#
0
#!/bin/bash
#count number of memory used by process
#writen by minghao
a=`ps aux |awk -F' ' '{print $6}' |grep -n '[1-9]'`
echo $a >1.txt
#count number of memory used by process
#writen by minghao
a=`ps aux |awk -F' ' '{print $6}' |grep -n '[1-9]'`
echo $a >1.txt
0
# ps -aux|awk '{print $6}'|sed '1d'
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
0
#!/bin/bash
##ps sum
#BY Lv.
sum=0
for i in `ps aux |awk -F" " '$6~/[0-9]/ {print $6}'`
do
sum=$[$sum+$i]
n=$[sum/1000]
done
echo "$n M"
##ps sum
#BY Lv.
sum=0
for i in `ps aux |awk -F" " '$6~/[0-9]/ {print $6}'`
do
sum=$[$sum+$i]
n=$[sum/1000]
done
echo "$n M"
0
#!/bin/bash
#ps 可以查看进程的内存占用大小,写一个脚本计算一下所有进程所占用内存大小的和。
#统计所有进程行数包括RSS
ps aux|awk '{print $6}'>/tmp/ram.txt
num_old=`cat /tmp/ram.txt |wc -l`
#除去RSS的行数,和文本内容
num_new=`expr $num_old - 1`
cat /tmp/ram.txt|tail -n $num_new > /tmp/newram.txt
#文件内容求和
sum=0
for i in `seq 1 $num_new`
do
num=`cat /tmp/newram.txt|head -n "$i"|tail -1`
sum=`expr $sum + $num`
done
#ps 可以查看进程的内存占用大小,写一个脚本计算一下所有进程所占用内存大小的和。
#统计所有进程行数包括RSS
ps aux|awk '{print $6}'>/tmp/ram.txt
num_old=`cat /tmp/ram.txt |wc -l`
#除去RSS的行数,和文本内容
num_new=`expr $num_old - 1`
cat /tmp/ram.txt|tail -n $num_new > /tmp/newram.txt
#文件内容求和
sum=0
for i in `seq 1 $num_new`
do
num=`cat /tmp/newram.txt|head -n "$i"|tail -1`
sum=`expr $sum + $num`
done
编辑回复