Thread: Timer without sleep();

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    52

    Timer without sleep();

    Hi there,

    This is probably a question you get quite often, but I cannot seem to find the answer in the FAQ nor can I find it in searching through this web site, so sorry about this.

    I am coding IRC Services, and everything works great, probably could be fixed up a tad, but that's not the issue here, so I'll stop rambling. I was wondering if it was possible to create a timer that runs a command every X minutes (changeable depending on the command you want to run), for example, timer_add(3600, (void*)some_cmd()); to create a timer that runs every hour, or possibly once an hour, because at the end of 'some_cmd()', I can just chuck it there.

    I have looked through the time.h and cannot see any way to do this. I have made structures with things stored, for example...

    Code:
    typedef struct zTimer aTimer;
    
    struct zTimer {
        char       *name;
        int          *often;
        time_t      starttime;
        aTimer    *next, *prev;
    };
    This isn't the one I used, but it is similar, and I created loops to allocate memory to it and everything, that seems all right, but I just can't figure out how to call upon it every X seconds/minutes.

    As you know, I can't use sleep(); because this halts everything, and IRC Services don't run too well if all commands are halted

    Any help would be MUCH appreciated, thanks again.
    - Daniel Wallace

  2. #2
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    See man pages on the function: signal(). The basica idea would be to set up an Alarm (SIGALRM) to be sent to your code after the desired number of seconds, specified as a parameter to this function.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    52

    Smile

    Thanks a lot

    Don't you just hate it when you know what to do and you don't know what to look up, heh.

    *goes out and buys some more books*


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 12:23 AM
  2. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  3. Problem with Sleep() #$@^#$%^
    By intruder in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2004, 06:46 AM
  4. Sleep is overrated...
    By Polymorphic OOP in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 01-24-2003, 12:40 PM