Re: Is this is an alarm or a signal handler

From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 04/30/04


Date: Fri, 30 Apr 2004 00:09:59 -0400

In article <uWikc.46$zz5.30@newsfe2-gui.server.ntli.net>,
 "LeTubs" <dlaw001@yahoonospam.co.uk> wrote:

> What I'm trying to is to start a timer, then a some time later
> determine if the timer counter has expired...if not wait untill
> that timer has expired.
> Now I don't know if this type of impletation is a signal/Alarm handler
> or something else. However thanks for the info

Establish a handler for the SIGALRM signal; the handler should set a
variable. Call alarm() -- it will set up a timer that will cause that
signal to be sent when the timer expires. Later, check the variable to
see if it has the value that the handler sets. If not, it means the
timer hasn't expired; call sigwait() to wait for the signal to interrupt
you.

Actually, I think it's probably easier without the timer. Start by
saving the time in a variable. Then some time later, get the current
time and compare it to the saved time. If the difference is less than
the expire time, call sleep() to wait for the remainder of the time.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


Relevant Pages

  • Re: Tesing of / bugs in new timerfd API
    ... following runs create a timer that expires 10 seconds from "now", ... s64 div) ... Forward the timer expiry so it will expire in the future. ...
    (Linux-Kernel)
  • Re: [Q] jiffies overflow & timers.
    ... As I said this is network layer. ... routine will be called at specified jiffies, ... so they will be processed at next timer tick. ... And add const for longest timer expires period - ...
    (Linux-Kernel)
  • [RFC][UPDATE PATCH 2/4] human-time soft-timer core changes
    ... > from the timer interrupt in software, i.e. jiffies. ... > timerintervals is used where we would have used the timer's expires ... extern int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue); ...
    (Linux-Kernel)
  • [RFC][PATCH 2/4] human-time soft-timer core changes
    ... from the timer interrupt in software, i.e. jiffies. ... timerintervals is used where we would have used the timer's expires ... extern int do_setitimer(int which, struct itimerval *value, struct itimerval *ovalue); ...
    (Linux-Kernel)
  • Re: Is this is an alarm or a signal handler
    ... >> determine if the timer counter has expired...if not wait untill ... > Establish a handler for the SIGALRM signal; ... > signal to be sent when the timer expires. ... call sigwait() to wait for the signal to interrupt ...
    (comp.unix.programmer)