Monitor Memory of a process


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Monitor Memory of a process
# 1  
Old 07-17-2009
Monitor Memory of a process

Hi,
I need to monitor the memory usage of a particular process continuously. As of now I am using the following command:
ps -fu <user name> -o pid,comm,vsz | grep <process_name> | grep -v grep

The output of this command gives me what i need except i want the output to keep getting updated every some time delay..
this command just gives me the memory usage at the time the command is run.

Please help !
# 2  
Old 07-17-2009
try:
Code:
while :
do
   your command
   sleep time_you_want
done

Run the program in background.
# 3  
Old 07-17-2009
if you are interested only to observe the output, that is, you don't want to save it in a file:
Code:
watch "ps -fu <user name> -o pid,comm,vsz | grep <process_name> | grep -v grep"

man watch for details
# 4  
Old 07-18-2009
This is something I through together once when I had to do something similar. (Actually at the time it was a one liner, but I'm really bored at the moment, so I played around)

Code:
(01:40:26+deco@DeCoBuntu)
[~]$cat track
#!/bin/bash
if [[ -z $1 ]];then
echo "Usage: `basename $0` <process to watch> <delay between checks>"
echo "If Delay not specified, default is 5 seconds"
exit
fi

usage=`top -b1 -n1|grep -i $1|awk '{print $10}'`
while true
do 
echo -ne "$1 is using $usage percent of the total memory"
echo -ne "\r"
if [[ -n $2 ]];then
sleep $2
else
sleep 5
fi
usage=`top -b1 -n1|grep -i $1|awk '{print $10}'`
done
(01:42:10+deco@DeCoBuntu)
[~]$./track
Usage: track <process to watch> <delay between checks>
If Delay not specified, default is 5 seconds
(01:45:45+deco@DeCoBuntu)
[~]$./track firefox 2
firefox is using 16.5 percent of the total memory

I'm pretty certain the switches on top could be done better, but honestly, I'm not very good at this kind of thing.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Best way to monitor use of memory resources for an RHEL instance

I wanted to know what is the best way to monitor use of memory on an RHEL server. We have 16 GB of memory for the RHEL instance but the usage at any time is more than 99%. I use /proc/meminfo on the server to check memory. I hope, my question is clear that what is the best way to monitor use of... (2 Replies)
Discussion started by: RHCE
2 Replies

2. Solaris

[DOUBT] Memory high in idle process on Solaris 10 (Memory Utilization > 90%)

Hi Experts, Our servers running Solaris 10 with SAP Application. The memory utilization always >90%, but the process on SAP is too less even nothing. Why memory utilization on solaris always looks high? I have statement about memory on solaris, is this true: Memory in solaris is used for... (4 Replies)
Discussion started by: edydsuranta
4 Replies

3. AIX

Script to monitor CPU , Memory

Hello. I am using AIX 6 and did lot of searches on google for this script and found so many results. Just thought to ask you being the real good place for centralised answer: a) Could you tell me the aix script, which may tell me If the CPU load is above e.g. 60% ? b) Could you tell me the AIX... (2 Replies)
Discussion started by: panchpan
2 Replies

4. UNIX for Dummies Questions & Answers

What to monitor for memory usage?

hi guys I am having a doubt about memory monitoring on linux system what I should be monitoring? memory usage? o swap usage? I am using some monitoring tools but I am confused to what monitor for alerting for example this case looks the memory usage is very high and it's like that all... (2 Replies)
Discussion started by: karlochacon
2 Replies

5. Linux

Monitor memory

Suppose our application limit use for up to 20GB of data. How to monitor the usage? Do we need to consider swap? Thanks. (2 Replies)
Discussion started by: zhshqzyc
2 Replies

6. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

7. Emergency UNIX and Linux Support

How to monitor a process memory utilization?

hi frnds, I want to monitor a particular process very closly on how much memory it is taking. i tried with TOP and PRSTAT commands that is not giving what exactly i need. In my application, there is a memory leak happening, i want to know when it is occuering, means which transcation is... (9 Replies)
Discussion started by: vij_krr
9 Replies

8. UNIX for Advanced & Expert Users

How often should I monitor the CPU and memory usage ?

Hi all, When you monitor the CPU and memory usage, how often do you do it ? Do it too often or too rarely will both cause the problem. So does anyone have hand-on experience ? And for my case, the requirement says that when CPU usage is above X% or memory usage is above Y%, I should reject... (5 Replies)
Discussion started by: qiulang
5 Replies

9. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

10. HP-UX

monitor memory usuage

Hi, We have HP-UX 11.23 and i want to use glance utility to monitor the memory usuage. Can someone tell me how to sort by memory usuage in glance utility? Thx (1 Reply)
Discussion started by: rockcapri
1 Replies
Login or Register to Ask a Question