LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 08-12-2009, 01:04 PM   #1
optimuz
LQ Newbie
 
Registered: Aug 2009
Posts: 5

Rep: Reputation: 0
Unhappy determine total memory used by some user/process


HI guys,

I am pretty new to linux,i would like to know how can i determine
the total/approx memory used by a single user. Example Top output is below

===========================================================================
top - 20:00:50 up 24 days, 2:48, 2 users, load average: 0.43, 0.40, 0.37
Tasks: 172 total, 2 running, 170 sleeping, 0 stopped, 0 zombie
Cpu(s): 4.3% us, 0.7% sy, 0.0% ni, 95.0% id, 0.0% wa, 0.0% hi, 0.0% si
Mem: 24954784k total, 23561312k used, 1393472k free, 318788k buffers
Swap: 2031608k total, 4k used, 2031604k free, 21011868k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
7172 rtx 16 0 73696 34m 3352 R 10 0.1 247:50.05 mysqld
5189 rtx 16 0 322m 316m 4268 S 3 1.3 60:50.34 some.f
5193 rtx 16 0 327m 321m 4264 S 2 1.3 60:14.19 some.f
16015 rtx 15 0 73696 34m 3352 S 1 0.1 139:45.09 mysqld
===========================================================================

From the Top output above i found that the memory usage is about 94%. There are about 45 processes owned by "rtx" user.Am wondering if there is any method i can use to determine the total/approx memory used by "rtx" user only...kindly advise..thanks alot
 
Old 08-12-2009, 01:57 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,953
Blog Entries: 5

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
Linux provides you a wealth of information under /proc including information about each process under /proc/<PID>, where PID is the process ID of the process you're interested in.

Type "man proc". It has lots of detail on one is available including the memory information you want.
 
Old 08-12-2009, 02:04 PM   #3
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 285

Rep: Reputation: 61
One way is to write a shell script which implements the following
Code:
ps -ef | grep username
# then call top with the PIDs as parameter
top p pid1 p pid2 > file
# then parse the output with awk or perl
 
Old 08-12-2009, 02:11 PM   #4
optimuz
LQ Newbie
 
Registered: Aug 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks alot jlightner & fpmurphy. i have found out the total 'rtx' process using #ps -ef | grep -i rtx | grep -v grep | wc -l.
I get a total of 45 processes running now.i can use the 'pmap' command to find the invidual PID memory usage...but am wondering how to find the accumulative memory usage by 'rtx'.I don't know how to parse using awk or perl
 
Old 08-12-2009, 02:48 PM   #5
optimuz
LQ Newbie
 
Registered: Aug 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Dear jlightner & fpmurphy,

After some RnD over google...i finally found the awk commands to get the total mem usage by a user/pid.

#ps aux | grep --exclude=grep rtx | grep -v grep | awk 'BEGIN{s=0;} {s=s+$6;}END{print s;}' // for total memory

#ps aux | grep –exclude=grep rtx |grep –v grep | awk ‘BEGIN{s=0;} {s=s+$6;} END {print s/45;}’ // for average memory


Thanks alot for the support given !
Have a great day
 
Old 08-13-2009, 07:23 AM   #6
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,953
Blog Entries: 5

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
One thing to be careful of: Linux unlike other *nix systems tends to show threads win the process list. Since every thread shares the same memory space with the other threads including the main process adding up memory becomes problematic because you're actually adding the same memory space multiple times. You need to either exclude threads in your ps output or be sure you're identifying which ones are using the same memory map.
 
Old 08-13-2009, 07:30 AM   #7
optimuz
LQ Newbie
 
Registered: Aug 2009
Posts: 5

Original Poster
Rep: Reputation: 0
got that jlightner...thanks
 
  


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
Intel64 RHEL system max 32 bit process user memory haimy Red Hat 2 06-03-2007 01:26 AM
Command to show each application/process memory usage and its total gn00kie Linux - Enterprise 2 09-21-2006 03:08 AM
Memory limitation for user process SwannAnderson Linux - Software 1 10-02-2005 08:12 PM
Determine process memory consumption ? shayer009 Linux - General 1 10-28-2004 02:03 PM
limiting cpu and memory usage by user process amitkush Linux - Security 2 07-04-2003 12:21 AM


All times are GMT -5. The time now is 07:40 AM.

Main Menu
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