Operating System - HP-UX
1748275 Members
3657 Online
108761 Solutions
New Discussion юеВ

sleeping for fractions of a second

 
SOLVED
Go to solution
Tim D Fulford
Honored Contributor

sleeping for fractions of a second

Hi

We have a test harness that we control via ksh scripts. The load is applied by simply issuing the commnd "rcd_client" (our code) a number of times & then sleeping for a few a second (simple "sleep 1"). However, this method has been criticized as being too "bursty"...

Is there a way of sleeping for less than 1 second? (C, perl, ksh, anything really)

Tim
-
8 REPLIES 8
Paula J Frazer-Campbell
Honored Contributor

Re: sleeping for fractions of a second

Hi Tim

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x04bfa2db8513d6118ff40090279cd0f9,00.html


Paula
If you can spell SysAdmin then you is one - anon
Paula J Frazer-Campbell
Honored Contributor
Solution

Re: sleeping for fractions of a second

Tim

look for nanosleep and Mr Voss's answer.

Paula
If you can spell SysAdmin then you is one - anon
Ceesjan van Hattum
Esteemed Contributor

Re: sleeping for fractions of a second

Make a mini c-program:
---------
#include
main (int argc,char **argv)
{
usleep((int)argv[1]);
}
---------
Name this file usleep.c
Compile it like this: gcc -o usleep usleep.c

Make it an executable: chmod a+x usleep

Run it like: usleep 3
and it will let you sleep for 3 MILLISECONDS

Regards,
Ceesjan
H.Merijn Brand (procura
Honored Contributor

Re: sleeping for fractions of a second

You can also use select () for that.

CeesJan, making a C program to just sleep 3 nanoseconds is complete non-snse :) You could as well just do return, given the fact that starting the process and ending it takes at least 3 nanoseconds, and also depends on the system load to return within the given time


in perl:

# usleep (seconds)
sub usleep ($)
{
select (undef, undef, undef, shift);
} # usleep

sleeping 10 microseconds would be

usleep (0.010);
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: sleeping for fractions of a second

That should be 10 milliseconds not microseconds. Sorry
Enjoy, Have FUN! H.Merijn
Tim D Fulford
Honored Contributor

Re: sleeping for fractions of a second

Personally 1 second sleep should be ok, it is just that the test department & customer want more control on how load is applied. Because the load is applied almost instantaneously we apply 20 loads, one after the other & sleep for 1 second and call this an average load of 10. We've got up to 2000 but the sockect creation/OS barfs out...

I think we could only sensibly sleep for 10 ms as "timeslice" is 10 (default)... But that is another question.

Many thanks for the replys, I will be doing all of them. 10pts a piece...

Tim
-
Tim D Fulford
Honored Contributor

Re: sleeping for fractions of a second

.... Results in.....

Perl wins.... I couldn't get the C programs to work. I'm less proficient in C than perl.

As said previously I only really need to sleep for up to 10ms, probably only 0.1s, so micro & nano second sleeps are too accurate... That said I'm sure with more than 2 minutes effort I could get the C stuff to work.

My loader will now be written in perl

Regards

Tim
-
H.Merijn Brand (procura
Honored Contributor

Re: sleeping for fractions of a second

Do I now get the Cup? :)
Enjoy, Have FUN! H.Merijn