Find Virtual address space size for process

Hi,

I am looking to work on unix systems which include (hp-ux, ibm aix, solaris and linux). I want to get the total virtual address space of a process, the used virtual memory i am able to get without any problem. I have tried using getrlimit and getrlimit64, but that gives only RLIMIT_INIFINITY or RLIMIT64_INFINITY if i use the getrlimit64.

Can you give me an idea on how much virtual addressable space is there in unix system for a user application to allocate as i need to do my memory allocations based on that?

Best regards,
uiqbal

The total virtual address space of a process depends on whether the process is 32-bit or 64-bit.
While the total virtual memory on the system is the sum of physical memory plus swap.

Hello,

My suggestions:

  1. sysconf() and _SC_PHYS_PAGES, not quite what you want and may be nonportable
  2. /usr/bin/free or /proc/meminfo or equivalent to cut total memory from. I think you can write separate [portable] script that gets the information on platforms you need.

Hi again,

I would always be working in 32 bit environment. My question is related to virtual memory or the memory user can allocate in a process -- i.e. the virtual address space of the process in user mode. How do i know that how much is reserved for the process on all the unix(help about any one of ibm aix, hp ux, sun os and linux welcomed)??

Best regards,
uiqbal

Your assumption seems wrong to me.

First off, Shamrock showed you how to get address space there is for a process versus how much "physical" virtual space is available through hardware and disk files.

The "hardware" part is OS dependent. Your assumption is that somehow the system reserves virtual space for each process. NO. It does not. The system gives memory space via sbrk() or brk() calls to any process requesting it. brk() fails when there is no more virtual space to be had. sbrk() returns SBRK_FAILED and brk() returns -1 on failure.

If the system "set aside" memory ahead of time, then these calls would not be needed.