INTELLIGENT WORK FORUMS FOR COMPUTER PROFESSIONALS
Contact US
Thanks. We have received your request and will respond promptly.
Log In
Come Join Us!
Are you a Computer / IT professional? Join Tek-Tips Forums!
Talk With Other Members
Be Notified Of Responses To Your Posts
Keyword Search
One-Click Access To Your Favorite Forums
Automated Signatures On Your Posts
Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Posting Guidelines
Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Students Click Here
Troubleshooting
How can I find out if I have a memory leak and if so, what is causing it? by cspilman
Posted: 26 May 06 (Edited 5 Aug 10)
This script will give a pretty good idea if you have memory leaks and what might be causing it. It's not the prettiest and can probably be simplified but it does what it was designed to do, find memory leaks if you have them. This has been tested to work on AIX 6.1 and below:CODE #!/bin/ksh echo "\n\nPlease wait..." if [ ! -f /tmp/ps.before ] ; then ps -e -o pid,vsz,ruser,etime,args | awk '!/defunct/{print $1","$2","$3","$4","$5,$6,$7}' > /tmp/ps.before fi ps -e -o pid,vsz,ruser,etime,args | awk '!/defunct/{print $1","$2","$3","$4","$5,$6,$7}' > /tmp/ps.after cat /tmp/ps.before /tmp/ps.after > /tmp/ps.total awk -F, '! /PID/{print $1,$2,$3,$4,$5,$6,$7}' /tmp/ps.before | while read pid vsz ruser etime command a b do num_procs=`grep -c "^${pid}," /tmp/ps.total` if [ "${num_procs}" -eq 2 ] ; then after_vsz=`awk -F, '/'"^${pid},"'/{print $2}' /tmp/ps.before` ((delta=vsz-after_vsz)) echo "${pid}\t${vsz}\t\t${after_vsz}\t\t${delta}\t${ruser}\t${etime}\t${command} $a $b" fi done > /tmp/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 /tmp/ps.after.tmp VSB=`awk '{ sum += $2 } END { print "Total VSZ Before: ", sum }' /tmp/ps.after.tmp` VSA=`awk '{ sum += $3 } END { print "Total VSZ After: ", sum }' /tmp/ps.after.tmp` DELTA=`awk '{ sum += $4 } END { print "Total Delta: ", sum }' /tmp/ps.after.tmp` rm /tmp/ps.after* rm /tmp/ps.total start_date=`ls -la /tmp/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 -c [d]efunct`"
Back to IBM: AIX FAQ Index
Back to IBM: AIX Forum