sleep exactly after n seconds (sleep finishing longer than specified)

2009-04-22 Thread Michael Alipio

Hi,

I have a script that forks a child. at the parent, i have a line that tells it 
to sleep for n seconds. Once the 3 seconds have passed, it will kill the child 
process.

I noticed that most of the time, sleep doesn't count exact seconds.. most of 
the time it's longer. Is there any way to sleep precisely for n seconds?


  

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: sleep exactly after n seconds (sleep finishing longer than specified)

2009-04-22 Thread Chas. Owens
On Wed, Apr 22, 2009 at 09:27, Michael Alipio daem0n...@yahoo.com wrote:

 Hi,

 I have a script that forks a child. at the parent, i have a line that tells 
 it to sleep for n seconds. Once the 3 seconds have passed, it will kill the 
 child process.

 I noticed that most of the time, sleep doesn't count exact seconds.. most of 
 the time it's longer. Is there any way to sleep precisely for n seconds?
snip

Not unless you are using a realtime OS.  Your process might not get
CPU time for n+m seconds.  Until your process gets CPU time it doesn't
matter what you put in sleep, nothing will happen.  You may be able to
schedule a process such that it will always have CPU time, but
performance will suffer for everything else (which is why realtime
OSes suck for everything but medical, weapon systems, and other tasks
that must have sub-microsecond timing).  You must trade speed for
precision.


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: sleep exactly after n seconds (sleep finishing longer than specified)

2009-04-22 Thread John W. Krahn

Michael Alipio wrote:

Hi,


Hello,


I have a script that forks a child. at the parent, i have a line that
tells it to sleep for n seconds. Once the 3 seconds have passed, it
will kill the child process.

I noticed that most of the time, sleep doesn't count exact seconds..
most of the time it's longer. Is there any way to sleep precisely for
n seconds?


Not really, but you can get finer grained timing using select()

perldoc -f select

Or the Time::HiRes module.

perldoc Time::HiRes



John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/