Find the answer to your Linux question:
Results 1 to 4 of 4
I'm fixing a memory leak, and need a function that returns the present available heap size, or heap usage. We tried getrusage() but it returns 0's............thus: maximum resident set size ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2010
    Location
    The Sillicon Valley, California
    Posts
    28

    function that returns memory size?


    I'm fixing a memory leak, and need a function that returns the present available heap size, or heap usage.

    We tried getrusage() but it returns 0's............thus:

    maximum resident set size 0
    integral shared memory size 0
    integral unshared data size 0
    integral unshared stack size 0
    page reclaims 0
    page faults 0
    swaps 0
    block input operations 0
    block output operations 2
    messages sent 0
    messages received 0
    signals received 0
    voluntary context switches 2
    involuntary context switches 1

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,752
    Please show the code you used, including variable declarations, #include files, etc.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Jan 2010
    Location
    The Sillicon Valley, California
    Posts
    28
    BTW, it's running on SunOS 5.9

    And, I need to programatically read the same 'size' that 'top' returns.

    int Error;
    struct sysinfo Resource_Metrics;

    Error = sysinfo( &Resource_Metrics );
    if( !Error )
    {
    printf("\n print_memory_usage.............. ");


    printf("\n Seconds since boot %ld", Resource_Metrics.uptime );
    printf("\n Total usable main memory size %ld", Resource_Metrics.totalram );
    printf("\n Available memory size %ld", Resource_Metrics.freeram );
    printf("\n Amount of shared memory %ld", Resource_Metrics.sharedram );
    printf("\n Memory used by buffers %ld", Resource_Metrics.bufferram );
    printf("\n Total swap space size %ld", Resource_Metrics.totalswap );
    printf("\n swap space still available %ld", Resource_Metrics.freeswap );
    printf("\n Number of current processes %ld", Resource_Metrics.procs );
    printf("\n Total high memory size %ld", Resource_Metrics.totalhigh );
    printf("\n Available high memory size %ld", Resource_Metrics.freehigh );
    printf("\n Memory unit size in bytes %ld", Resource_Metrics.mem_unit );
    printf("\n %ld", Resource_Metrics. );
    printf("\n %ld", Resource_Metrics. );
    printf("\n %ld", Resource_Metrics. );
    printf("\n %ld", Resource_Metrics. );
    printf("\n %ld", Resource_Metrics. );
    printf("\n %ld", Resource_Metrics. );

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,752
    Well, since this is a Linux Programming & Scripting forum, I have to ask why you think this will work the same way on Solaris? Wouldn't it be more appropriate to post this question to the user forums on the Sun/Oracle Solaris web site?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •