sleep(3) uses longjmp and SIGALRM

David Sherman dave at lsuc.uucp
Thu Sep 29 03:59:11 AEST 1988


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.

No wonder I get funny interactions with my other uses of setjmp
and SIGALRM.  I'm surprised some of it works at all.

The manual doesn't suggest sleep(3) shouldn't be used in conjunction
with setjmp or SIGALRM.  But setjmp's certainly aren't nestable.
Has anyone else run into this issue?  Comments?

David Sherman
The Law Society of Upper Canada
-- 
{ uunet!attcan  att  pyramid!utai  utzoo } !lsuc!dave



More information about the Comp.unix.wizards mailing list