Re: nanosleep with small value

From: Eric Piel
Date: Thu Nov 17 2005 - 12:32:18 EST

11/17/2005 05:55 PM, linux-os (Dick Johnson) wrote/a Ãcrit:
On Thu, 17 Nov 2005, Dag Nygren wrote:

real 0m8.000s
user 0m0.000s
sys 0m0.000s

On an unprivilged account, I get this with

Script started on Thu 17 Nov 2005 11:44:47 AM EST
LINUX> time ./xxx
sched_setscheduler returned: -1
Operation not permitted

real 0m2.000s
user 0m0.000s
sys 0m0.001s
LINUX> uname -r
LINUX> exit
Script done on Thu 17 Nov 2005 11:45:07 AM EST

From the root account where the scheduler could be set:

Script started on Thu 17 Nov 2005 11:45:29 AM EST
[root@chaos root]# time /tmp/xxx

real 0m2.001s
user 0m0.000s
sys 0m0.001s
[root@chaos root]# exit

Script done on Thu 17 Nov 2005 11:45:53 AM EST

... essentially the same thing. And 2 seconds, not 8.

The HZ value for my kernel is 1000. It you are at 100 HZ,
that might explain it.
No, it means he is at 250 HZ.

Note that nanosleep() doesn't claim to be able to sleep
less than the resolution of some kernel timer. It just takes
parameters in seconds and nanoseconds.

In general small nanosleep() returns between 1/HZ and 2/HZ. In this code, the sleep is (indirectly) synchronised on a tick so it's always 2/HZ, the worse!

1000 small nanosleeps take therefore 1000 * 2/HZ s = 8s :-)

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at