-
how to idle?
background: I'm working on watchdog system where an Arduino sends text to the PC via USB. if the PC doesn't answer back within a certain time, the Arduino will actuate a latching relay and force a restart of the PC... with that in mind..
I've figured out how to make the program work on asynchronous comms using SIGIO (I forgot to mention I'm working under Linux Mint/Cinnamon (ubuntu based system)
my question is.. what's the best way to have the program do nothing while it's waiting for a SIGIO? (right now I'm working console C. eventually I want to figure out how to make it run as a service...)
also.. this is eventually going to be used on a windows XP machine.. I realize linux generally doesn't need a watchdog. i just happen to use linux on my desktop)
-
Like this perhaps?
Code:
while ( true ) {
sleep(86400);
}
-
Salem: I am currently using sleep.. is that the best method? does the time spent sleeping matter? I.E sleeping for maybe 1 second, or 100 seconds etc? i think generally the micro controller will poll the PC about once a minute.
-
All the work is being done in your SIGIO handler apparently.
> i think generally the micro controller will poll the PC about once a minute.
If you sleep for 1 second, then sleep() will return normally, and it will go back to sleep 59 out of 60 times.
The other sleep will return an interrupted sleep, then go back to sleep.
It's not doing anything either way, so it really makes no difference.
-
Alright.. thanks for the info !