天天看点

SHELL下根据进程号得到内存,并截取为整数

柳鲲鹏

这样可以判断当前内存情况:

# 由参数传递进来
pid=$1
 
text=`cat /proc/$pid/status | grep VmRSS`
 
pos=`expr index "$text" " "`
text=`echo $text | cut -c $pos-`
 
pos=`expr index "$text" " "`
pos=`expr $pos - 1`
memory=`echo $text | cut -c 1-$pos`
 
echo memory=---$memory+++