Process sleeping < sleep time

Process sleeping < sleep time

Post by Michael Paravicin » Wed, 12 Jan 2000 04:00:00



Sorry that should read "this is not the case"

Quote:>a signal can interrupt the sleep period, but this is the case. Can anyone

 
 
 

Process sleeping < sleep time

Post by Michael Paravicin » Wed, 12 Jan 2000 04:00:00


Hi,
I have a piece of code that uses the clock_gettime function and sleep
function in essentially the following way:

...
clock_gettime(START_TIME)
...
sleep(X)
...
clock_gettime(END_TIME)
...

To my way of thinking when I subtract START_TIME from END_TIME, the
difference should be the sleep time plus the additional processing time.
However what I am seeing if that the time difference can be substantially
less than X. (eg for a 5 sec sleep, the diff can be 4.2 sec). I realise that
a signal can interrupt the sleep period, but this is the case. Can anyone
offer an explanation? Or has anyone seen this sort of thing before?

Thanks in Advance,
Michael.

 
 
 

Process sleeping < sleep time

Post by Harald Kirsc » Wed, 12 Jan 2000 04:00:00



> clock_gettime(START_TIME)
> ...
> sleep(X)
> ...
> clock_gettime(END_TIME)
> ...

> To my way of thinking when I subtract START_TIME from END_TIME, the
> difference should be the sleep time plus the additional processing time.
> However what I am seeing if that the time difference can be substantially
> less than X. (eg for a 5 sec sleep, the diff can be 4.2 sec). I realise that

This is really hard to believe. Maybe you want to post some real code,
not just pseudocode.

Harald Kirsch

--
P.S.: Never ever mail me copies of your posts.
---------------------+---------------------------------------------


 
 
 

Process sleeping < sleep time

Post by mars1.. » Thu, 13 Jan 2000 04:00:00


Quote:> To my way of thinking when I subtract START_TIME from END_TIME, the
> difference should be the sleep time plus the additional processing
time.
> However what I am seeing if that the time difference can be
substantially
> less than X. (eg for a 5 sec sleep, the diff can be 4.2 sec). I
realise that
> a signal can interrupt the sleep period, but this is the case. Can
anyone
> offer an explanation? Or has anyone seen this sort of thing before?

I quote a man page on sleep()

Actual suspension time can be less than that requested for two reasons:

     + Scheduled wakeups occur at fixed 1-second intervals (on the
  second, according to an internal clock), and

     + Any caught signal terminates the sleep following execution of
    that signal's catching routine.

End quote

Therefore, if you call sleep at say 00:00:00.90 and sleep for 5 seconds,
the wakeup will occur at 00:00:05.00, which is actually only 4.1
seconds.
--
# unrm /
ksh: unrm:  not found
# man cpio

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

Process sleeping < sleep time

Post by Russ Allber » Thu, 13 Jan 2000 04:00:00




>> To my way of thinking when I subtract START_TIME from END_TIME, the
>> difference should be the sleep time plus the additional processing
>> time.  However what I am seeing if that the time difference can be
>> substantially less than X. (eg for a 5 sec sleep, the diff can be 4.2
>> sec).
> This is really hard to believe. Maybe you want to post some real code,
> not just pseudocode.

I don't find it particularly hard to believe; it depends on the
implementation of sleep.  For example, sleep(3b) (the compatibility one)
on Solaris says:

     sleep() suspends the current process from execution for the number of
     seconds specified by the argument.  The actual suspension time may be
     up to 1 second less than that requested, because scheduled wakeups
     occur at fixed 1-second intervals, and may be an arbitrary amount
     longer because of other activity in the system.

Similarly, sleep(3c) on HP-UX says:

      sleep() suspends the current process from execution for the number
      of seconds specified by the argument.

      Actual suspension time can be less than that requested for two
      reasons:

           o  Scheduled wakeups occur at fixed 1-second intervals (on the
              second, according to an internal clock), and

           o  Any caught signal terminates the sleep following execution
              of that signal's catching routine.

So if you're getting a 4.2 second timing on a 5 second sleep, it sounds
like something like the above is happening.

--

 
 
 

1. Sleep in ksh script ignored until the sleep time expires

Hi,

I'm trying to write a ksh script that traps certain signals (HUP,
INT, QUIT, TERM).  For testing, I wrote the following script:

   #!/bin/ksh
   trap 'print Signal caught' HUP INT QUIT TERM
   while :; do
      print "Sleeping ..."
      sleep 30
   done

I ran the script and opened another terminal session and issued a 'kill'
command followed by the PID # of the above script (say 11980):
   $ kill -INT 11980

The script above didn't seem to trap the sent signal immediately.  But
instead, completes the sleep (30 seconds) and then acknowledge the signal
(by invoking the command specified after the "trap" built-in command).

I posted a question to IBM, but the AIX Support person was unable to
duplicate the situation.  He indicated during his testing that the signal
was caught by the "trap" command immediately without waiting for the sleep
to expire when he sent a signal using 'kill' to the PID of the ksh script.

The script, however, did get interrupted immediately if I type Ctrl-C
on the same terminal session running the script -- but this won't help me.

Has anyone seen this problem?  Any known solution?

Thanks ..

----------------------------------------------------------------------
Okki Tranggana                    |    

tel:   (408) 974-7323             |    1 Infinite Loop, MS:76-2TI
fax:   (408) 974-1560             |    Cupertino, CA 95014
--
----------------------------------------------------------------------
Okki Tranggana                    |    

tel:   (408) 974-7323             |    1 Infinite Loop, MS:76-2TI
fax:   (408) 974-1560             |    Cupertino, CA 95014

2. Source level kernel debugger for HP-UX

3. Bug in glibc-2.1.1: sleep(0) sleeps 10ms

4. Dial-In PPP on Solaris 2.5.1

5. sleep() sleeps the thread or the proc?

6. More On Missing Core File

7. sleeping time of process

8. Slow DSL downloads under Netscape

9. How can a process put another process to sleep?

10. can the process let another process sleep & wakeup?

11. sleep < 1 second

12. sleep < 1s

13. How do you "sleep" for < 1 second?