LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-20-2010, 04:43 AM   #1
emymcse
LQ Newbie
 
Registered: Jun 2006
Posts: 10

Rep: Reputation: 0
Calculate total memory consumed by user


Hello,

is there a way to calculate the total memory consumed by user ?

Thanks
 
Old 09-20-2010, 04:49 AM   #2
anurag2202
LQ Newbie
 
Registered: Aug 2010
Posts: 20

Rep: Reputation: 0
Solution

We can check it by using 'free' command.
 
Old 09-20-2010, 05:52 AM   #3
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
Code:
# ps -eo size,pid,user,cmd | awk '$3 ~ /username/ { mem+=$1 } END { print mem }'
 
Old 09-20-2010, 02:03 PM   #4
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by emymcse View Post
is there a way to calculate the total memory consumed by user ?
You don't mean used (which I think was the intent behind post #2), and you do mean by 'a single user' (which I think was the intent behind post #3) and not 'all (ordinary?) users'.

The code in post #3 didn't work for me...which was a pity, as I thought it was a neat idea. Can you explain the awk part, as awk isn't something I normally use, please?
 
Old 09-20-2010, 04:48 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,145

Rep: Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124
Change username to a valid user name, and try again.
Merely checks for that username and accumulates the first field (size). This is (probably) not what you would expect "size" to represent - see the manpage.
 
Old 09-21-2010, 04:08 AM   #6
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by syg00 View Post
Change username to a valid user name, and try again.
That's what I did, first time, and the outcome was a blank line. This is intended to work in bash, or some other shell?
 
Old 09-21-2010, 04:20 AM   #7
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
@salasi: What shell are you using? Does 'ps -u <your_username>' show anything?
 
Old 09-23-2010, 03:43 AM   #8
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
Originally Posted by quanta View Post
@salasi: What shell are you using? Does 'ps -u <your_username>' show anything?
(sorry about the delay): I was about to say bash, but it was really konsole 2.5 (kde 4.5.1), if that makes a difference. The output from ps -u is in the form:

Code:
 3295 ?        00:00:00 gvfs-fuse-daemo
 3298 ?        00:02:33 knemo
 3302 ?        00:00:01 soffice.bin
 3303 ?        00:00:01 klipper
 3307 ?        00:00:00 gvfs-gdu-volume
 3312 ?        00:00:00 gvfs-gphoto2-vo
 3314 ?        00:00:54 kwalletd
 3316 ?        00:00:02 gvfs-afc-volume
 3321 pts/2    00:00:00 bash
 3331 ?        00:00:00 gconfd-2
 3338 ?        00:00:00 gconf-helper
 3356 ?        00:00:00 kwalletmanager
 5643 ?        00:00:11 kate
 5756 pts/0    00:00:00 bash
 8523 pts/4    00:00:00 bash
 8532 pts/5    00:00:00 bash
( 'random' extract from the middle of the output)
 
Old 09-23-2010, 04:02 AM   #9
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
No, no. konsole is a terminal. The shell is: sh, bash, csh, ksh, ... You can check which shell you are using with 'echo $0', 'ps -p $$', ...

Could you please copy-paste when you run command in post #3?
 
Old 09-23-2010, 04:02 AM   #10
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
No, no. konsole is a terminal. The shell is: sh, bash, csh, ksh, ... You can check which shell you are using with 'echo $0', 'ps -p $$', ...

Could you please copy-paste when you run command in post #3?
 
Old 09-23-2010, 04:37 AM   #11
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,070

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Quote:
You can check which shell you are using with 'echo $0', 'ps -p $$',
Code:
 echo $0', 'ps -p $$
/bin/bash, ps -p 8523
Quote:
Originally Posted by quanta View Post
No, no. konsole is a terminal. The shell is: sh, bash, csh, ksh, ... You can check which shell you are using with 'echo $0', 'ps -p $$', ...

Could you please copy-paste when you run command in post #3?
Code:
 ps -eo size,pid,user,cmd | awk '$3 ~ /username/ { mem+=$1 } END { print mem }'
..now can you start answering some questions...
 
Old 09-23-2010, 04:46 AM   #12
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
Did you change username to your login name?
 
Old 09-23-2010, 05:26 AM   #13
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Look at output of the first part on it's own.
ps -eo size,pid,user,cmd

Since you just need the size and user, how about:
ps -eo size,user

Sometimes when an output on the left hand side of a pipe is blank, it's because of an error on the right hand side, such as a missing or aliased command.

Also, what does "ps --version" return? I've seen similar one-liners using ls & awk that didn't work out right when I tried them because of a small difference in the output such as how recent dates were printed.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
All memory being consumed by only a few processes rtr_87 Linux - Software 5 01-25-2010 09:36 PM
determine total memory used by some user/process optimuz Linux - Newbie 6 08-13-2009 07:30 AM
memory consumed by a process ZAMO Linux - General 1 02-19-2009 09:22 AM
How to calculate the total RAM used by several processes rjlee Linux - Software 3 07-19-2007 05:33 PM
I don't understand how to calculate the total value of (ls -l) greeting Linux - General 7 08-12-2006 05:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:03 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
Open Source Consulting | Domain Registration