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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-12-2009, 01:04 PM
|
#1
|
|
LQ Newbie
Registered: Aug 2009
Posts: 5
Rep:
|
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
|
|
|
|
08-12-2009, 01:57 PM
|
#2
|
|
Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,644
|
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.
|
|
|
|
08-12-2009, 02:04 PM
|
#3
|
|
Member
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 280
Rep:
|
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
|
|
|
|
08-12-2009, 02:11 PM
|
#4
|
|
LQ Newbie
Registered: Aug 2009
Posts: 5
Original Poster
Rep:
|
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 
|
|
|
|
08-12-2009, 02:48 PM
|
#5
|
|
LQ Newbie
Registered: Aug 2009
Posts: 5
Original Poster
Rep:
|
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 
|
|
|
|
08-13-2009, 07:23 AM
|
#6
|
|
Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,644
|
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.
|
|
|
|
08-13-2009, 07:30 AM
|
#7
|
|
LQ Newbie
Registered: Aug 2009
Posts: 5
Original Poster
Rep:
|
got that jlightner...thanks 
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 07:29 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|