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 ...
- 10-01-2010 #1Just 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?
- 10-04-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,952
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!
- 10-05-2010 #3Just Joined!
- Join Date
- Oct 2010
- Posts
- 5
my code:
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.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; }
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.
- 10-05-2010 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,952
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!
- 10-06-2010 #5Just Joined!
- Join Date
- Oct 2010
- Posts
- 5
More code...
The ... stuff definitely has nothing to do with libgtop2 (all just working with copied variables), so this should pretty much be the complete 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); } }
- 10-06-2010 #6Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,952
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!



