LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Blogs > pinga123
User Name
Password

Notices

Rate this Entry

How to track Application causing Memory Leak Using Ps command?

Posted 05-04-2011 at 03:19 AM by pinga123
Updated 05-04-2011 at 03:27 AM by pinga123 (Header edited)

Normally Most of applications uses some part of memory and release it after their operation is over or Application is closed.

However some applications don't just give up memory and leads to memory being utilized heavily.

For RAM consumption simulation i have used a script ( source : http://stackoverflow.com/questions/4...r-a-user-defin )

Code:
#!/bin/bash

echo "Provide sleep time in the form of NUMBER[SUFFIX]"
echo "   SUFFIX may be 's' for seconds (default), 'm' for minutes,"
echo "   'h' for hours, or 'd' for days."
read -p "> " delay

echo "begin allocating memory..."
for index in $(seq 1000); do
    value=$(seq -w -s '' $index $(($index + 100000)))
    eval array$index=$value
done
echo "...end allocating memory"

echo "sleeping for $delay"
sleep $delay
saved the script with name /tmp/ramload.sh

As per the script owner it had consumed 570M to 575M physical memory* for the specified time period of 5 minutes.
Ran the command.
Code:
# ./ramload.sh
Provide sleep time in the form of NUMBER[SUFFIX]
SUFFIX may be 's' for seconds (default), 'm' for minutes,
'h' for hours, or 'd' for days.
> 5m
begin allocating memory...


You can track such applications using following ps command.

Code:
#ps aux --sort rss
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2 0.0 0.0 0 0 ? S< 01:54 0:00 [migration/0]
root 3 0.0 0.0 0 0 ? SN 01:54 0:00 [ksoftirqd/0]
root 4 0.0 0.0 0 0 ? S< 01:54 0:00 [watchdog/0]
root 5 0.0 0.0 0 0 ? S< 01:54 0:00 [migration/1]
root 4732 0.0 0.4 10732 4848 tty7 Ss+ 01:55 0:01 /usr/bin/Xorg :
root 4746 0.0 0.9 24444 9784 ? SN 01:55 0:00 /usr/bin/python
gdm 4756 0.0 1.5 30488 15540 ? Ss 01:55 0:00 /usr/libexec/gd
root 8900 55.9 2.7 32188 28584 pts/1 R+ 23:58 0:25 /bin/bash ./ramload.sh

Run the command after some time.

Code:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 4731 0.0 0.3 27392 3740 ? Sl May03 0:00 /usr/libexec/gdm-rh-security-token-helper
root 4318 0.0 0.4 13256 4692 ? S May03 0:00 python ./hpssd.py
root 4732 0.0 0.4 10732 4848 tty7 Ss+ May03 0:01 /usr/bin/Xorg :0 -br -audit 0 -auth /var/gdm/:0.Xauth -nolist
root 4746 0.0 0.9 24444 9784 ? SN May03 0:00 /usr/bin/python -tt /usr/sbin/yum-updatesd
gdm 4756 0.0 1.5 30488 15540 ? Ss May03 0:00 /usr/libexec/gdmgreeter
root 8900 69.5 5.5 60624 57276 pts/1 S+ May03 0:54 /bin/bash ./ramload.sh

You can observe the last entry which is
Code:
/bin/bash ./ramload.sh
Is a reason behind memory utilization.

(
Note:
1) Only few entries are displayed from output due to its size.
2) Normally ps aux --sort pmem is used for sorting the ps output using the memory but it has some bug .
see below link for more info
http://www.linuxquestions.org/questi...=1#post4344941
)
From above output we can say that
Code:
./ramload.sh
process is using the max memory.You need to fire the command at regular interval to check if the process is culprit behind memory crisis.
Posted in Uncategorized
Views 3960 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 03:22 AM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration