Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!snorkelwacker!apple!metaphor!dattatri From: dattatri@metaphor.Metaphor.COM (Dattatri) Newsgroups: comp.unix.internals Subject: Millisecond Timers Keywords: Using setitimer and pause Message-ID: <1487@metaphor.Metaphor.COM> Date: 2 Oct 90 18:05:41 GMT Organization: Metaphor Computer Systems, Mountain View, CA Lines: 25 As I see it, the easiest way to provide a millisecond timer is as follows. 1. Set up a handler for SIGALRM. 2. Set up and start the timer for the required amount of time. 3. Then pause for a signal. nap(time) { int timerHandler(); /* Set up handler for SIGALRM. Could use sigvec/sigaction also */ signal(SIGALRM, timerHandler); /* Insert code to set timer for x milliseconds and start the timer */ pause(); } timerHandler() { } If you expect other signal(s) to be received during the 'pause', necessary arrangements should be made to check the signal etc (which is trivial). This method cannot be used if SIGALRM is already being used for other tasks. Note that the pause() returns after the signal handler has completed. Kayshav Dattatri -- (dattatri@metaphor.com)