Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Memory leak

Status
Not open for further replies.

tech005

MIS
Dec 11, 2003
36
0
0
US
How can i find which process is causing a memory leak? My server is paging very gradually.
 
You could also use this script:

Code:
#!/bin/ksh

if [ ! -f /usr/local/out/ps.before ] ; then
       ps -e -o pid,vsz,ruser,etime,args | \
awk '{print $1","$2","$3","$4","$5,$6,$7,$8,$9,$10,$11,$12}'  | \
grep -v defunct > /usr/local/out/ps.before
fi

ps -e -o pid,vsz,ruser,etime,args | \
awk '{print $1","$2","$3","$4","$5,$6,$7,$8,$9,$10,$11,$12}' | \
grep -v defunct > /usr/local/out/ps.after

cat /usr/local/out/ps.before /usr/local/out/ps.after > /usr/local/out/ps.total



cat /usr/local/out/ps.after | \
awk -F, '! /PID/{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11}' | \
while read pid vsz ruser etime command a b c d e f
do
       num_procs=`grep "^${pid}," /usr/local/out/ps.total | wc -l | tr -d ' '`
       if [ "${num_procs}" -eq 2 ] ; then
               after_vsz=`grep "^${pid}," /usr/local/out/ps.before | awk -F, '{print $2}'`
               ((delta=vsz-after_vsz))
               echo "${pid}\t${vsz}\t\t${after_vsz}\t\t${delta}\t${ruser}\t${etime}\t${command} $a $b $c $d $e $f"
       fi
done > /usr/local/out/ps.after.tmp

clear
echo "PID\tVSZ SIZE BEFORE\tVSZ SIZE AFTER\tDELTA\tUSER\tELAPSED TIME\tCOMMAND"
echo "---\t---------------\t--------------\t-----\t----\t------------\t-------"
sort +3 /usr/local/out/ps.after.tmp

VSB=`cat /usr/local/out/ps.after.tmp | awk '{ sum += $2 } END { print "Total VSZ Before:                ", sum }'`
VSA=`cat /usr/local/out/ps.after.tmp | awk '{ sum += $3 } END { print "Total VSZ After:         ", sum }'`
DELTA=`cat /usr/local/out/ps.after.tmp | awk '{ sum += $4 } END { print "Total Delta:                   ", sum }'`

start_date=`ls -la /usr/local/out/ps.before | awk '{print $6,$7}'`

echo "\n\nRunning against ps.before file with date of:  ${start_date}"
echo "\n\n${VSB}"
echo "${VSA}"
echo "${DELTA}"
echo "Total Defunct Processes Found:    `ps -ef | grep [d]efunct | wc -l | tr -d ' '`"

I threw this together at the last minute as we were having suspected memory leak problems so I know there are much more efficient ways to do some of things in here. It is functional though and gives you an idea at what your problem areas might be.

Hope this helps.

Regards,
Chuck
 
@mrn

As far as thread52-1174789, the above script I gave is a rewrite of that exact code as it didn't give me some information that I needed (i.e. user, command, etc).

Regards,
Chuck
 
Chuck,

I'm not accusing you plagiarism, simply pointing tech005 to a previous thread on the subject.

tech005 - It's always worth doing a search on the subject and looking at the FAQ here on TT.

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
I understand, and I didn't mean to come off defensive either. I just wanted to state the differences in my script from the original one.

There's always more than one way to do something in UNIX.

Regards,
Chuck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top