[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Feature requests for sleep and a new program

From: Bob Proulx
Subject: Re: Feature requests for sleep and a new program
Date: Thu, 29 Nov 2001 21:26:22 -0700

> Hi,
> I'd like to propose two new features to "sleep":
> 1) Sub-Second resolution

GNU sleep version 2.0a and later implements that.  The NEWS file

 * sleep accepts floating point arguments on command line

And the info page includes:

   Historical implementations of `sleep' have required that NUMBER be
an integer.  However, GNU `sleep' accepts arbitrary floating point

The latest test release is available at:


> 2) Wait for ms multiple
> You can't control loop cycle times with sleep: If you "sleep 1" and
> your loop payload takes 0.1 second you end up with a 1.1+X second
> cycle time. If we wait for a timer modulo interval to flip over, we
> have exact control over loop cycle time. An implementation could
> look like:
> a=timerfunction mod interval
> aa=a
> while a>= aa
>       sleep 10 ms
>       a=aa
>       a=timerfunction mod interval
> wend
> We could use a "-m" parameter for this changed behavior

You could 'time' the loop payload, extract the real time, subtract
that from the desired loop time, guarentee that it is non-negative,
sleep for that value.  Implementation left as an excercise to the
reader.  :-) [Hint: The "time --format='%e\n'" option would probably
be useful.]

> A new program could supplement "nice". In some (rare) cases you want
> to control the maximum CPU load a program can generate. It could be
> dome via signals. To allow a maximum CPU load of 0.5 for a program
> you can send a TSTOP signal , wait 0.5 seconds, send CONT and wait
> 0.5 seconds and so on.
> I know that programs can intercept signals but it'll work for most
> programs.

low_priority_task_to_run &
while sleep 0.5; do
  kill -STOP $! || break
  sleep 0.5
  kill -CONT $! || break



reply via email to

[Prev in Thread] Current Thread [Next in Thread]