1 /* @(#)ualarm.c 1.1 (Berkeley) 03/14/85 */ 2 3 #include <sys/time.h> 4 5 #define USPS 1000000 /* # of microseconds in a second */ 6 7 /* 8 * Generate a SIGALRM signal in ``usecs'' microseconds. 9 * If ``reload'' is non-zero, keep generating SIGALRM 10 * every ``reload'' microseconds after the first signal. 11 */ 12 unsigned 13 ualarm(usecs, reload) 14 register unsigned usecs; 15 register unsigned reload; 16 { 17 struct itimerval new, old; 18 19 new.it_interval.tv_usec = reload % USPS; 20 new.it_interval.tv_sec = reload / USPS; 21 22 new.it_value.tv_usec = usecs % USPS; 23 new.it_value.tv_sec = usecs / USPS; 24 25 if (setitimer(ITIMER_REAL, &new, &old) == 0) 26 return (old.it_value.tv_sec * USPS + old.it_value.tv_usec); 27 /* else */ 28 return (-1); 29 } 30