I may be a little overzealous with daemons here, but shouldn't a daemon be capable of doing this job? If you're not using a *nix machine, I would have no clue how you would go about it though...
The system() function is a good one, far better than the exec() alternatives in my opinion.
But it seems a priori that having an endless while() loop would be inefficient. It'd be like asking repeatedly "Is it time yet? How about now? Now? now?!" Disclaimer: you could have very well written something like:
This is a good solution because it spares CPU cycles. The alternative that I assume you have is something like:Code:while(true) { do_check(); //checks for whatever you're looking for sleep(5*60*1000); // sleeps for 5 * 60 seconds, or 5 minutes }
This is worse because there are more CPU cycles dedicated to checking the difference in time. That's inefficient.Code:unsigned int time = current_time(); while(true) { if(current_time() - time == /* 5 minutes */) { do_check(); //whatever you're checking time = current_time(); // change the time variable } }
I myself am inclined to use recursion, but I'm just a whacky coder like that.
Just my two cents...






Reply With Quote