Shell脚本查看进程内存真实占用情况脚本查看进程内存真实占用情况
代码如下:
#!/bin/bash
#****************************************************************#
# ScriptName: pm
# Author: osdba
# Create Date: 2010-01-31
# Modify Author:
# Modify Date: 2010-01-31
# Function: show processes memory used
#***************************************************************#
function getpidmem()
{
cat /proc/$1/smaps 2>/dev/null |awk /
‘BEGIN{
total_size=0;
total_rss=0;
total_shared_clean=0;
total_shared_dirty=0;
total_private_clean=0;
total_private_dirty=0;
total_swap=0;
mem_size=0;
mem_rss=0;
mem_shared_clean=0;
mem_shared_dirty=0;
mem_private_clean=0;
mem_private_dirty=0;
mem_swap=0;
}
{
if($1 ~ /^Size:/)
{
mem_size=$2;
}
else if($1 ~ /^Rss:/)
{
mem_rss=$2;
}
else if($1 ~ /^Shared_Clean:/)
{
mem_shared_clean=$2;
}
else if($1 ~ /^Shared_Dirty:/)
{
mem_shared_dirty=$2;
}
else if($1 ~ /^Private_Clean:/)
{
mem_private_clean=$2;
}
else if($1 ~ /^Private_Dirty:/)
{
mem_private_dirty=$2;
}
else if($1 ~ /^Swap:/)
{
mem_swap=$2;
}
else
{
if(ipcmem_start==1)
{
ipc_size=mem_size;
ipc_rss=mem_rss;