Can Unix sleep in terms of mili/micro?

Lawrence E. Freil lef at dogwood.atl.ga.us
Sat Sep 22 00:15:32 AEST 1990


For System V.3 or greater why not use the following code:

/**************************************************************************
 * Function Name         : nap
 * Argument Description  : time to sleep in milliseconds
 * Global References     : (a % by the name indicates an alteration occurs)
 * Author                : Lawrence Freil
 * Function Description  :
 *      This routine uses the poll system call to delay a specified number
 *      of milliseconds.  Poll called without any file descriptors but with
 *      a timeout specified works for this purpose.
 *
 **************************************************************************/
int
nap(int timeout)
{
  struct pollfd foo[1];
  int status;

  status = poll(foo, 0L, timeout);
  return status;
}

You can also do the same thing for berkley with the select call (no files,
just the timeout.)

	Lawrence Freil	       		    Usenet/DDN:lef at dogwood.atl.ga.us
        National Science Center Foundation  Phone:(404)-828-8459
	P.O. Box 1648
	Augusta, Ga 30903

-- 
	Lawrence Freil	       		    Usenet/DDN:lef at dogwood.atl.ga.us
        National Science Center Foundation  Phone:(404)-828-8459
	P.O. Box 1648
	Augusta, Ga 30903



More information about the Comp.unix.internals mailing list