Calculate total memory consumed by user
Hello,
is there a way to calculate the total memory consumed by user ? Thanks |
Solution
We can check it by using 'free' command.
|
Code:
# ps -eo size,pid,user,cmd | awk '$3 ~ /username/ { mem+=$1 } END { print mem }' |
Quote:
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? |
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. |
Quote:
|
@salasi: What shell are you using? Does 'ps -u <your_username>' show anything?
|
Quote:
Code:
3295 ? 00:00:00 gvfs-fuse-daemo |
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? |
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? |
Quote:
Code:
echo $0', 'ps -p $$ Quote:
Code:
ps -eo size,pid,user,cmd | awk '$3 ~ /username/ { mem+=$1 } END { print mem }' |
Did you change username to your login name?
|
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. |
All times are GMT -5. The time now is 12:35 PM. |