1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Obtaining process size

Discussion in 'C++' started by sszd, Sep 11, 2010.

  1. sszd

    sszd New Member

    Sep 11, 2010
    Likes Received:
    Trophy Points:
    Does anyone know how to "programmatically" obtain the size of a process in memory on a Solaris 8 operating system? What I'm trying to do is obtain something similar to what you get from the "top" or "pmap" shell command. I do not want to run a system command and parse the results either. From what I've learned so far, there is a /proc directory with this type of information (containing subdirectories of the process id's for all the processes running). I've been able to read the various files contained within the subdirectory of interest for the process I'm experimenting with and I've filled the appropriate structures (I think) from the procfs.h header file. I'm pretty sure I'm reading these files correctly because I've successfully confirmed some of the data (like the pid and ppid for instance). I'm also fairly sure the file I'm really interested in is the psinfo file. My problem is every time I read this file from within my process, and then examine the process size, I always get 4,294,967,296 bytes (which is 4 GB, which is the "max" size of a 32 bit process, not the current size as it's running). I know the process doesn't start that large because I can monitor it with the "top" command and watch as it grows. In fact, it starts very small and eventually grows to 4 Gigs after about 15 minutes. I don't understand why I don't get the same results from within my process by reading these /proc files periodically. I'm either reading the wrong file, or I don't understand what I'm really doing. I've found very little information on this online, and the man pages don't really tell you what files are associated with which structures in the procfs.h header file. It's mostly been trial and error trying to determine what to read and where to put the results. Is the psinfo file not the correct file? I've also looked at various other files like the "status", "map", and "as" files. If anyone can please help me with this, or at least point me in the right direction, I'd really appreciate it. Thank you.

Share This Page