Link to home
Start Free TrialLog in
Avatar of beer9
beer9Flag for India

asked on

how to calculate total memory used in freebsd ?

I am using these two command in freebsd box.

ps aux | awk '{memory +=$4}; END {print memory }'
5134.9

ps aux | awk '{memory +=$6}; END {print memory }'
246991968


whereas total physical memory is
sysctl -a | grep -i hw.physmem
hw.physmem: 4289929216

What is the difference between the output of %Mem and RSS of 'ps' command ?
ASKER CERTIFIED SOLUTION
Avatar of gheist
gheist
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of beer9

ASKER

if 32bit machine can't use more than 4GB, then how come "ps aux | awk '{memory +=$4}; END {print memory }'" gives around 5GB(5134.9) size ? pmem should be maximum of 100, shouldn't it ?
There are shared libraries and SHM segments that count multiple times if you run daemonized servers and/or databases.
Avatar of beer9

ASKER

yeah.. I am running above in mysql server.. which have around 900 established connection. So I want to find how much memory mysql processes are using..
opesource databases are notoriously intrackable in regard of memory usage.
you should take sum of virtual memory sizes, and retract shared memory size from each process using shared memory (as seen by ipcs -m)
Then dynamic loader comes around - it loads one instance of shared library ans shares between multiple processes.
Avatar of beer9

ASKER

on more info I need, how can I identify whether particular process is a shared libraries or SHM segments, I will count those process only once to get the accurate result.

P.S: what is SHM ?
Avatar of beer9

ASKER

Excellent!
You can get full path to executable from ps, then use ldd command to see which modules can be loaded.

SHM - SysV shared memory