Hi,
Assuming if you call sleep every 1 sec then performance wise it will
affect,
I think sleep is implemented as a system call(takes some time to exeucte
i.e switching from user to kernel and viceversa,getting the current time
etc..) + check you are performing will take some time.hence you will not
land up at exactly 10 sec boundary.
instead use signal functionality(viz SIGALRM).
Regards,
Santosh
----- Original Message -----
From: "Rohan Almeida" <[email protected]>
To: <linux-india-programmers-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Sent: Monday, April 26, 2004 4:52 PM
Subject: [LIP] sleep function - perform activity every 10 seconds
>
> Hi,
>
> I have a process which needs to perform an activity
> every 10 seconds - starting from the 10 sec boundary.
>
> Excuse my terminology, but this should it make it more clear.
>
> time activity
> -----------------
> 12:18 process started
> 12:19 sleep
> 12:20 ACTIVITY
> 12:21 sleep
> 12:22 sleep
> ..... .....
> 12:30 ACTIVITY
>
>
> Easy to understand. Once the process starts, I get the current time.
> Check if the seconds end in digit zero. If yes - perform activity.
> sleep 1 second. repeat.
>
> Then i begin to think - why should I execute sleep call every
> second when i know the interval? So after first activity, I
> modify the sleep interval to 10 seconds. It still works.
>
> Questions:
> * I personally prefer calling sleep every second, than doing it
> every 10 seconds. Performance wise - any issues?
> * Is the sleep call accurate or does any rounding take place?
> As the 10 second boundary is imperative and not just the interval
> of 10 seconds. i.e. After a sleep call of 10 seconds, am I guaranteed
> that i will land on a 10 second boundary assuming a start at such a
> boundary and that the process needs to be run indefinitely.
>
> I hope I'm clear enough. :-)
>
> --
> Rohan
>
>
>
>
>
>
>
>
-------------------------------------------------------
This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek
For a limited time only, get FREE Ground shipping on all orders of $35
or more. Hurry up and shop folks, this offer expires April 30th!
http://www.thinkgeek.com/freeshipping/?cpg=12297
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.