site  contact  subhomenews

Freememapplet now more efficient

June 19, 2008 — BarryK
I'm using the inotify mechanism with pup_event_backend_d and pup_event_frontend_d to send messages to other programs. pup_event_backend_d uses this to send messages to pup_event_frontend_d and now pup_event_frontend_d sends messages to freememapplet. pup_event_backend_d and pup_event_frontend_d write files into /tmp, which has a tmpfs mounted on it, so no writes to permanent storage are involved.

Previously, freememapplet had a polling loop, every 10 seconds was the default. Now with inotify it basically goes to sleep until a file (/tmp/eventd_sizefreem) gets modified, and pup_event_frontend_d only modifies that file when the free memory changes by >= 1MB. So, freememapplet is now extremely efficient, very low system resources.

For those interested in the programming side of this, it was remarkably easy to put this into freememapplet. I got 'inotify.h' and 'inotify-syscalls.h' out of the 'inotail' package, and put this in freememapplet.cc:

#include "inotify.h"
#include "inotify-syscalls.h"

int ifd;
int wd;

ifd = inotify_init();
if ( ifd < 0 ) { sleep(5); continue; }

wd = inotify_add_watch(ifd, "/tmp/eventd_sizefreem", IN_MODIFY);
if ( wd < 0 ) { sleep(2); continue; }

if((fp = fopen("/tmp/eventd_sizefreem","r")) == NULL) { sleep(5); continue; }
fgets(memfree,sizeof memfree,fp);
fclose(fp);


Comments

freememapplet
Username: ttuuxxx
Hi Barry, I'm in the middle of making a icewm package for woof and could use your lastest sources for freememapplet, I can only find it compiled for puppy, do you have a url to the source code, Thanks Barry ttuuxxx

freememapplet_xlib-404
Username: BarryK
"Look in the obvious place: linked off the Puppy download page: http://puppylinux.com/download/index.html Which are: http://puppylinux.ca/puppyfiles/sources/alphabetical/f/ or http://puppylinux.asia/sources/BarryKauler/alphabetical/f/ it's the '404' version.


Tags: puppy