[ale] Mixing Alarm and Sleep
Kevin J. Schmidt
kschmidt at mindspring.com
Mon Jan 21 15:00:01 EST 2002
>From the sleep man page:
BUGS
sleep() may be implemented using SIGALRM; mixing calls to
alarm() and sleep() is a bad idea.
Using longjmp() from a signal handler or modifying the
handling of SIGALRM while sleeping will cause undefined
results.
I think you might be able to use nanosleep (man nanosleep) for what you
want.
On Mon, 2002-01-21 at 14:53, Chris Fowler wrote:
>
> Ah! I'm having some issues using the alarm() call and the sleep() call in the same program. The alarm call is in a library function. Basically, another piece of source code. It uses the alarm to timeout on sending
> and receiveing data over udp. I nede to loop and sleep for 30 seconds. The sleep is not sleeping for 30 seconds. Bacically it would look like this.
>
>
>
> send.c - part of a library
> --------------------------
>
> catchAlarm(int signum)
> {
> ALARM=1
> }
>
> int
> send{char *ip)
> {
> signal(SIGALRM, catchAlarm)
> alarm(60);
>
> /* send */
>
> /* receive */
>
> alarm(0);
>
> return CODE;
> }
>
>
> --------------------------------
> daemon.c
>
>
> int
> main(int argc, char *argv[])
> {
>
> int code;
>
> for(;;)
> {
> code = send("127.0.0.1");
>
> /* Do something */
>
> sleep(30);
> }
>
> reutrn 0;
> }
>
>
> ---
> This message has been sent through the ALE general discussion list.
> See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
> sent to listmaster at ale dot org.
>
--
-kjs, 0x4765656b
---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
sent to listmaster at ale dot org.
More information about the Ale
mailing list