Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

how to calculate total memory used in freebsd ?

Posted on 2008-10-12
Last Modified: 2013-11-22
I am using these two command in freebsd box.

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

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

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 ?
Question by:beer9
  • 4
  • 4
LVL 62

Accepted Solution

gheist earned 250 total points
ID: 22703675
pmem - percent of RAM taken by program (exluding swapped ans shared)
rss - same in kilobytes.

Actually "man ps" manual page lists keywords.

4GB physical memory is unaddressable by 32bit app fully. Some address space is eaten by shared mem, and some by kernel.

Is there any perceived problem you are solving or just plain curiosity?

Author Comment

ID: 22720102
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 ?
LVL 62

Expert Comment

ID: 22726779
There are shared libraries and SHM segments that count multiple times if you run daemonized servers and/or databases.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

ID: 22728576
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..
LVL 62

Expert Comment

ID: 22729223
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.

Author Comment

ID: 22787070
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 ?

Author Closing Comment

ID: 31505433
LVL 62

Expert Comment

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

SHM - SysV shared memory

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question