Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!mit-eddie!husc6!purdue!decwrl!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.unix.wizards Subject: Re: sleep(3) uses longjmp and SIGALRM Message-ID: <844@goofy.megatest.UUCP> Date: 29 Sep 88 21:30:26 GMT References: <1988Sep28.135914.25444@lsuc.uucp) Organization: Megatest Corporation, San Jose, Ca Lines: 26 From article <1988Sep28.135914.25444@lsuc.uucp), by dave@lsuc.uucp (David Sherman): ) I have a fairly complex CAI system that's used for legal education ) here. It uses pipes, longjmp, SIGUSER and pause(2) to allow the student ) to hit an interrupt key and change the level of instruction at any point. ) It also uses sleep(3) here and there, and SIGALRM to log off idle users. ) With all the various UNIXisms that interact, the programs occasionally ) exhibit strange behaviour, which I'd never been able to pinpoint. ) ) Today someone asked me why sleep(3) is a library routine rather ) than a system call, which I'd always thought it was. (This is a ) v7-based UNIX, Perkin-Elmer's Edition VII.) So I read the code, ) and was startled to find it uses SIGALRM and pause, with a longjmp ) to put you back where you were. The man-page on the Sun3 (BSD4.2 based) is explicit: sleep is implemented by setting an interval timer and paus- ing until it expires. The previous state of this timer is saved and restored. I would recommend that you process all signals, sleeps, selects, etc, through a central location. The "notifier" in Sun's sunview package would suffice, but I don't know if its source is available. In any case, it should not be too difficult to implement it. Good luck.