Find the answer to your Linux question:
Results 1 to 6 of 6
I have a while(1) loop, and the error is: glibtop: open (/proc/stat): Too many open files This error occurs after about a half hour to an hour of running. I've ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2010
    Posts
    5

    libgtop2:


    I have a while(1) loop, and the error is:
    glibtop: open (/proc/stat): Too many open files

    This error occurs after about a half hour to an hour of running.

    I've tried running this multiple times, both with using glib_close() at the end of the loop, using glib_init() and glib_close() at beginning/end, and just using glib_init(). The strange thing is these have no effect on the actual glib_get functions.

    Anybody familiar with libgtop and have a solution?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    11,167
    Please post your code here. It sounds like you are not releasing resources (file handles) appropriately.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Oct 2010
    Posts
    5
    my code:
    Code:
    #include <glibtop.h>
    #include <glibtop/cpu.h>
    #include <glibtop/mem.h>
    #include <glibtop/uptime.h>
    ...
    int main()
    {
    ...
    glibtop_init();
    ...
    while(1)
    {
    glibtop_get_cpu (&cpu);
    glibtop_get_mem(&memory);
    glibtop_get_uptime(&uptime);
    ...
    }
    return;
    }
    As far as I can see, it uses a global server, which it only allocates on the init(). I've tried putting a glib_close() inside of the while loop (assuming it spawns a new server every time it calls the functions) but that has no effect.

    The documentation for libgtop2, while complete, is very lacking in useful examples, so I'm really not sure how to properly use the other functions to specify a server handle which I control.

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    11,167
    Well, that shows how you are using glibtop in your code, but not the rest of it. Something is consuming file descriptors and you still are not providing enough information to rule out either your code or the glibtop code.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    Oct 2010
    Posts
    5

    More code...

    Code:
    #include <stdio.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <cmath>
    #include <glibtop.h>
    #include <glibtop/cpu.h>
    #include <glibtop/mem.h>
    #include <glibtop/uptime.h>
    ...
    static glibtop_cpu cpu;
    static glibtop_mem memory;
    static glibtop_uptime uptime;
    static unsigned long long lastCpuTotalSum = 0;
    static unsigned long long lastCpuUsedSum = 0;
    static unsigned long long lastCpuIOWaitSum = 0;
    static bool firstCpuCalc = true;
    ...
    int main()
    {
    ...
    glibtop_init();
    ...
    while( 1 )
    {
        ...
        //Get CPU/Memory status
        glibtop_get_cpu (&cpu);
        glibtop_get_mem(&memory);
        glibtop_get_uptime(&uptime);
        ...
        int memUsed = (int)(memory.user/(1024*1024));
        int totalMem = (int)(memory.total/(1024*1024));
        double memPercentFree = (double)(memUsed) /
                                (double)(totalMem);
        ...
            if( !firstCpuCalc )
        {
          unsigned long long cpuusedsum = cpu.user + cpu.sys + cpu.nice + cpu.iowait + cpu.irq + cpu.softirq;
          unsigned long long cpuusedsumdiff = cpuusedsum - lastCpuUsedSum;
          unsigned long long cpuiowaitsumdiff = cpu.iowait - lastCpuIOWaitSum;
          unsigned long long cputotalsumdiff = cpu.total - lastCpuTotalSum;
          float percentUsed = (float)(cpuusedsumdiff) / (float)(cputotalsumdiff);
          float percentIOWait = (float)(cpuiowaitsumdiff) / (float)(cputotalsumdiff);
          int currentPercentUsed = round(percentUsed * 100);
          //printf("Percent Used: %d\n", currentPercentUsed);
          int currentIOWaitUsed = round(percentIOWait * 100);
          ...
          lastCpuUsedSum = cpuusedsum;
          lastCpuIOWaitSum = cpu.iowait;
          lastCpuTotalSum = cpu.total;
        }
        else
        {
          firstCpuCalc = false;
          ...
          lastCpuUsedSum = cpu.user + cpu.sys + cpu.nice;
          lastCpuTotalSum = cpu.total;
        }
    
        //Uptime
        double uptimeSec = uptime.uptime;
        int uptimeMin = (int)uptimeSec / 60;
        int uptimeMinClock = uptimeMin % 60;
        int uptimeHour = uptimeMin / 60;
        int uptimeHourClock = uptimeHour % 24;
        int uptimeDay = uptimeHour / 24;
        int uptimeDayClock = uptimeDay % 365;
        ...
        glibtop_close();
        sleep(CYCLE_TIME);
    }
    }
    The ... stuff definitely has nothing to do with libgtop2 (all just working with copied variables), so this should pretty much be the complete code.

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    11,167
    Well, I was trying to see if something you were doing would open file descriptors/sockets and not release them. Unless it is in the code you didn't provide, indicated by the elipses ..., then I can't say what is causing your problem. Have you tried updating the glibtop libraries?
    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
  •