On Thu, 17 Nov 2005, Dag Nygren wrote::
No, it means he is at 250 HZ.
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
LINUX> uname -r
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
[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.
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!
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.