Questions about physical memory and hard disk.

  • Follow


Hi,

There are two questions:
1, How to get the available physical memory in solaris 2.7 system? I know I
can get the totle physical memory with the c function sysconf, but how can I
get the available physical memory with C code.

2, How to get hard disk with c code just like the command df -k . in the
solaris 2.7 system?


Thanks,
Ben


0
Reply Benjamin 12/10/2003 8:51:16 AM

Benjamin Wang wrote :

> There are two questions:
> 1, How to get the available physical memory in solaris 2.7 system? I know I
> can get the totle physical memory with the c function sysconf, but how can I
> get the available physical memory with C code.

and why won't you use the C function sysconf() ?

-- 
DINH V. Hoa,

etPan! - newsreader, mail user agent -- http://libetpan.sf.net/etpan

0
Reply DINH 12/10/2003 10:17:31 AM


See http://docs.sun.com/db/doc/816-0213/6m6ne38dd?a=view

You can call sysconf() an get the same information as the OS sysconf

Benjamin Wang wrote:
> Hi,
> 
> There are two questions:
> 1, How to get the available physical memory in solaris 2.7 system? I know I
> can get the totle physical memory with the c function sysconf, but how can I
> get the available physical memory with C code.
> 
> 2, How to get hard disk with c code just like the command df -k . in the
> solaris 2.7 system?
> 
> 
> Thanks,
> Ben
> 
> 

0
Reply Joseph 12/10/2003 3:55:39 PM

"Benjamin Wang" <zwang2@lucent.com> wrote in message
news:br6mqf$qmk@netnews.proxy.lucent.com...

> 1, How to get the available physical memory in solaris 2.7 system? I know
I
> can get the totle physical memory with the c function sysconf, but how can
I
> get the available physical memory with C code.

    Define what you mean by "available". Do you mean only memory that is
literally not in use? What about memory that contains clean copies of data
on disk and can be discarded immediately -- is that "available"?

> 2, How to get hard disk with c code just like the command df -k . in the
> solaris 2.7 system?

    Probably 'statvfs' is what you want.

    DS


0
Reply David 12/10/2003 6:33:20 PM

Hi David,

The available physical memory means the physical memory unused.Sorry for
confused. Is there a c system call to get it?

I have tried statvfs, and worked well. But man page mentions that there are
bugs for NFS. So, for NFS, how could I get hard disk data?

Thanks,
Ben

"David Schwartz" <davids@webmaster.com> wrote in message
news:br7otg$jfc$1@nntp.webmaster.com...
>
> "Benjamin Wang" <zwang2@lucent.com> wrote in message
> news:br6mqf$qmk@netnews.proxy.lucent.com...
>
> > 1, How to get the available physical memory in solaris 2.7 system? I
know
> I
> > can get the totle physical memory with the c function sysconf, but how
can
> I
> > get the available physical memory with C code.
>
>     Define what you mean by "available". Do you mean only memory that is
> literally not in use? What about memory that contains clean copies of data
> on disk and can be discarded immediately -- is that "available"?
>
> > 2, How to get hard disk with c code just like the command df -k . in the
> > solaris 2.7 system?
>
>     Probably 'statvfs' is what you want.
>
>     DS
>
>


0
Reply Benjamin 12/11/2003 3:53:39 AM

"Benjamin Wang" <zwang2@lucent.com> wrote in message
news:br8poh$8oo@netnews.proxy.lucent.com...

> The available physical memory means the physical memory unused.Sorry for
> confused. Is there a c system call to get it?

    It will be near zero on most modern UNIX machines. They use all
available memory pretty much all the time. You will find that only memory on
the shelf is unused. The OS will keep copies of disk data in memory just in
case someone wants to read them again shortly.

    My home Linux machine, for example, has 512Mb of physical memory. But it
always has 19Mb free no matter how busy it is. That's because it only keeps
memory free for emergencies (like a large burst of network data) and, by
design, keeps about 3%-4% of the physical memory free. Otherwise, it's more
sensible to keep disk data in memory. In fact, right now my system has 215Mb
of memory holding copies of data read from or written to disk just in case
it's accessed again.

    For all practical purposes, free memory is memory not installed in a
UNIX machine.

    DS


0
Reply David 12/11/2003 11:00:45 AM

On Wed, 10 Dec 2003 11:17:31 +0100, DINH Viet Hoa wrote:

> Benjamin Wang wrote :
> 
>> There are two questions:
>> 1, How to get the available physical memory in solaris 2.7 system? I
>> know I can get the totle physical memory with the c function sysconf,
>> but how can I get the available physical memory with C code.
> 
> and why won't you use the C function sysconf() ?

First, sysconf() is not a "C" function. It's an API provided by most UNIX
like operating systems. You won't find sysconf() in any C language
standard. Second, as Mr. Shwartz has pointed out on any UNIX system that
has been running for any length of time the amount of available (i.e.,
"free") memory will normally be close to zero. On my home system with
1.25GiB of physical memory sysconf(_SC_AVPHYS_PAGES) reports 1386 pages
available as I write this. But most of the "non-free" pages are actually
part of various caches which will shrink if need be. I would have no
problem starting a program which needed more than 1386 pages of memory.

The question posed by the O.P. is essentially meaningless. A more
meaningful question might be "what is the minimum amount of memory
required by the operating system?" Subtracting that value from the amount
of physical memory would provide an approximation of the maximum amount of
memory any one process could utilize. But even that is an
oversimplification since there are other processes running with their own
dynamic memory needs which can't be ignored if you don't want the system
to thrash.

Most people asking this question do so because they want their program to
dynamically adjust its memory use. In practice it simply isn't possible.
At least not in a straightforwad manner such as by asking for how much
"available" memory there is. The simplest approach that is practical is to
use sysconf(_SC_PHYS_PAGES) to find out how much physical memory is
present then calculate a fraction of that value. But note that in a NUMA
architecture that will probably not yield a useful value since you
wouldn't normally want a process to use "remote" memory.
0
Reply Kurtis 12/13/2003 10:55:50 PM

6 Replies
303 Views

(page loaded in 0.056 seconds)

Similiar Articles:













7/25/2012 4:02:42 AM


Reply: