Thread: how to idle?

  1. #1
    Registered User
    Join Date
    Jan 2024
    Posts
    6

    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)

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,675
    Like this perhaps?
    Code:
    while ( true ) {
        sleep(86400);
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2024
    Posts
    6
    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.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,675
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Jan 2024
    Posts
    6
    Alright.. thanks for the info !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Idle curiosity: What is a Block?
    By QuadraticFighte in forum C Programming
    Replies: 4
    Last Post: 10-17-2010, 04:02 PM
  2. Waiting For A Thread To Idle
    By SMurf in forum Windows Programming
    Replies: 2
    Last Post: 10-10-2008, 06:31 PM
  3. Idle Issue.
    By Charmy in forum C++ Programming
    Replies: 7
    Last Post: 06-24-2005, 06:10 AM
  4. Function that get CPU Idle
    By daskmaster in forum Windows Programming
    Replies: 5
    Last Post: 02-16-2003, 09:13 AM
  5. Sleep or Idle
    By Barjor in forum Windows Programming
    Replies: 3
    Last Post: 02-07-2002, 09:37 AM

Tags for this Thread