perform operation at a certain interval - Unix

This is a discussion on perform operation at a certain interval - Unix ; Say I want to perform the action at a certain timeout, like fire an event. I figured out how to do every n number of seconds, but not 1.5 seconds. Here is what I have.Please suggest how to handle my ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: perform operation at a certain interval

  1. perform operation at a certain interval

    Say I want to perform the action at a certain timeout, like fire an
    event. I figured out how to do every n number of seconds, but not 1.5
    seconds. Here is what I have.Please suggest how to handle my case:

    extern int PUBLISH_TIMEOUT;

    void Publish()
    {
    static int local_time=time(NULL);

    int current_time = time (NULL);
    if((current_time+PUBLISH_TIME)>local_time)
    {
    fireEvent();
    local_time=current_time;
    }
    }

  2. Re: perform operation at a certain interval

    puzzlecracker writes:
    >Say I want to perform the action at a certain timeout, like fire an
    >event. I figured out how to do every n number of seconds, but not 1.5
    >seconds. Here is what I have.Please suggest how to handle my case:
    >
    >extern int PUBLISH_TIMEOUT;
    >
    >void Publish()
    >{
    > static int local_time=time(NULL);
    >
    > int current_time = time (NULL);
    > if((current_time+PUBLISH_TIME)>local_time)
    > {
    > fireEvent();
    > local_time=current_time;
    > }
    >}


    Read the man page for the time(2) system call:

    $ man 2 time

    Then, follow the SEE ALSO section and examine in
    turn each of the references.

    scott

  3. Re: perform operation at a certain interval

    On Sep 19, 5:03 am, puzzlecracker wrote:
    > Say I want to perform the action at a certain timeout, like fire an
    > event. I figured out how to do every n number of seconds, but not 1.5
    > seconds. Here is what I have.Please suggest how to handle my case:
    >
    > extern int PUBLISH_TIMEOUT;
    >
    > void Publish()
    > {
    > static int local_time=time(NULL);
    >
    > int current_time = time (NULL);
    > if((current_time+PUBLISH_TIME)>local_time)
    > {
    > fireEvent();
    > local_time=current_time;
    > }
    >
    > }


    There are probably numerous ways, but the most frequent I've
    seen has been to do a poll or a select with a timeout and an
    empty list of fd's. If your system supports it, you should use
    nanosleep. (According to the Posix documentation, it is
    optional. But most systems have it, I think.)

    --
    James Kanze (GABI Software) email:james.kanze@gmail.com
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

+ Reply to Thread