LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices



Reply
 
Search this Thread
Old 03-31-2008, 01:46 AM   #1
ajeetraina
Member
 
Registered: Jun 2007
Location: India
Distribution: Ubuntu,Red Hat, Fedora
Posts: 292

Rep: Reputation: 30
Script for Memory Usage??


I have a JAVA Processes running and all I need to find out what total memory it is utilising.If its usage exceed 500 MB (My memory is 1GB)it should throw error or report the % memory Usage.
IS there any script which can display the same??
 
Old 03-31-2008, 03:03 AM   #2
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,442

Rep: Reputation: 70
You can get the memory usage of a process with a command like
Code:
ps -C command-name -o rss=
 
Old 03-31-2008, 04:07 AM   #3
livetoday
Member
 
Registered: Jun 2006
Location: India
Distribution: RHEL,Suse,Fedora
Posts: 106

Rep: Reputation: 15
and percentage of 'used physical memory' by

Quote:
ps aux | grep command | awk '{print $4,$NF}'
 
Old 03-31-2008, 04:40 AM   #4
ajeetraina
Member
 
Registered: Jun 2007
Location: India
Distribution: Ubuntu,Red Hat, Fedora
Posts: 292

Original Poster
Rep: Reputation: 30
The command threw:
vjs@vjs:~$ ps -C java -o rss=
393504
What is this???What does rss means?

LEmme me tel you issue in detail.
I am tring to write a script which shouldnt allow Java application to exceed 500MB irrespective of total RAM Size.
It Means if RAM is 30GB also,it should retrict it to 500MB.
How can I do this?
All i tried a attempt:
Code:
mem=`ps aux | awk '{print $4"\t"$11}' | sort | uniq -c | awk '{print $2" "$1" "$3}' | sort -nr | grep java |cut -c1-4`;

echo "-------------------------------------------------------------------------";

echo "% MEMORY CONSUMED BY JAVA PROCESSES";

echo "--------------------------------------------------------------------------";

echo "$mem";

limit=50;

if [ $mem -ge $limit ]; then

echo "Memory has reached its limit"         // you can add the favourable condition like mail, restarting applications etc.

else

echo "Memory still not crossed the limit"

fi
Output
Code:
vjs@vjs:~$ ./memscript.sh
------------------------------------
% MEMORY CONSUMED BY JAVA
------------------------------------
38.6
./memscript.sh: line 9: [: mem: integer expression expected
Memory still not crossed the limit
vjs@vjs:~$
This is not what I am attempting at.It simpl restrict to 50% but i want it to restrict to 500MB only.
Pls help

Last edited by ajeetraina; 03-31-2008 at 04:45 AM.
 
Old 03-31-2008, 10:18 AM   #5
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,442

Rep: Reputation: 70
Quote:
Originally Posted by ajeetraina View Post
The command threw:
vjs@vjs:~$ ps -C java -o rss=
393504
What is this???What does rss means?
resident set size - The amount of real RAM the process is using. That number is in KB so divide by 1024 if you want the MB equivalent. Set that value for your mem variable.
 
Old 03-31-2008, 10:22 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,693
Blog Entries: 54

Rep: Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961Reputation: 2961
If you want to restrict memory in Java processes, shouldn't you use the -Xms/-Xmc startup parameters instead of scripting something?
 
Old 03-31-2008, 10:27 AM   #7
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,442

Rep: Reputation: 70
Quote:
Originally Posted by unSpawn View Post
If you want to restrict memory in Java processes, shouldn't you use the -Xms/-Xmc startup parameters instead of scripting something?
that'd do it. Good call. Excert from the java man page:

Code:
             -Xmsn
                Specify the initial size, in bytes, of the memory allocation
                pool. This value must be a multiple of 1024 greater than 1MB.
                Append the letter k or K to indicate kilobytes, or m or M to
                indicate megabytes. The default value is chosen at runtime
                based on system configuration. For more information, see
                HotSpot Ergonomics
                Examples:

                       -Xms6291456
                       -Xms6144k
                       -Xms6m

             -Xmxn
                Specify the maximum size, in bytes, of the memory allocation
                pool. This value must a multiple of 1024 greater than 2MB.
                Append the letter k or K to indicate kilobytes, or m or M to
                indicate megabytes. The default value is chosen at runtime
                based on system configuration. For more information, see
                HotSpot Ergonomics
                Examples:

                       -Xmx83886080
                       -Xmx81920k
                       -Xmx80m
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
X hangs after prolonged usage ... memory usage goes upto 195MB duryodhan Slackware 18 05-10-2007 07:16 PM
Memory Usage Spaw Usage Swappiness Issues joelunch Linux - Software 3 01-04-2006 07:16 PM
getting realtime info on memory usage-cpu and harddrive usage steering Linux - Newbie 5 03-03-2005 09:43 PM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 05:45 AM
Controlling CPU usage & memory usage Saravana babu Linux - Software 0 02-18-2004 06:55 AM


All times are GMT -5. The time now is 11:50 PM.

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