[comp.unix.questions] Millisecond clock

burzio@mmlai.UUCP (Tony Burzio) (08/11/90)

The folowing program for millisecond sleep works under HP-UX SYSV,  so
it should work on an ATT (serious finger crossing :-).  Compile with:

cc -O timer.c -o timer

--------------------------------- cut here -----------------------------------

#include <signal.h>
#include <time.h>

void myhandler() {}
usleep(usec)
int usec;
{
	int sigret;
	struct itimerval rttimer;
	struct itimerval old_rttimer;
	struct sigaction *act, *oact ; 

	rttimer.it_value.tv_sec     = ( (float) usec)  / 1000000;
	rttimer.it_value.tv_usec    = 
		((float) usec) - ((float) rttimer.it_value.tv_sec * 1000000.0);
	rttimer.it_interval.tv_sec  = 0;
	rttimer.it_interval.tv_usec = 0;

	(void) signal(SIGALRM,(myhandler));
	setitimer (ITIMER_REAL, &rttimer, &old_rttimer);
	pause();
}

main ()
{
	usleep(500000);
}

--------------------------- cut here  --------------------------------------

*********************************************************************
Tony Burzio               * OH!  You have to turn it ON first!
Martin Marietta Labs      *
mmlab!burzio@uunet.uu.net *	- First day, DOS user.
*********************************************************************

guy@auspex.auspex.com (Guy Harris) (08/12/90)

>The folowing program for millisecond sleep works under HP-UX SYSV,  so
>it should work on an ATT (serious finger crossing :-).

Crossing the fingers is a good idea here.  "Xxx works under HP-UX SYSV,
therefore it should work on an [arbitrary] ATT [System V release]" isn't
a valid deduction.  While some systems, including HP-UX, have
"setitimer()", which your program uses, vanilla AT&T System V releases
prior to S5R4 don't have it.