To read all comments associated with this story, please click here.
"It would be stupid to implement something that consumes the CPU like that when you only need it for 1 minute a day."
Isn't it what USB host adapters do with polling (unlike standard interrupt driven serial ports)? :-)
"A good example, none the less.. of what NOT to do. :-)"
I think we need a HOWNOTTO here. :-)
I really once progged something ALMOST that stupid
.
I have a Rollei slide projector which has an RS232 interface to the computer.
When I wrote a program which lets me "remote control" the projector by the computer I had a problem: How to waste time as efficient as possible?
I was (and am) no great shakes at timers, especially as I wanted to get my timing correct within 1/10th of a second, and the standard Linux timers allowed only for 1 second granularity.
I started with adding and subtracting 1 to a variable within a loop, but as you can guess, this led to 100% CPU utilisation. I ended up with asking the projector for its status, which led to maximum traffic on the 9600baud RS232, but at least kept my CPU at sane 8%.
:)





Member since:
2005-07-06
Write a shell script that does what you want but uses so much CPU time they will gladly give you cron job access just to get you to quit using the "work around".
#!/bin/sh
while true ; do
if [ "$(date +%k:%M)" = "05:00" ] ; then
do_something_important ;
fi ;
done ;
Note: The functional part of that script will run for the entire minute of 5:00 a.m. Add a check to make it only run once. For the other 1,439 minutes of the day, it will just peg the CPU at 100% for no good reason.
Edited 2007-04-17 21:46