gpkinman@sdrc.UUCP (Tim Kinman) (09/07/88)
I would like to implement an alarm utility within my application but I am concerned about the side effects it will have on my existing code. It is my understanding that reads from a terminal, wait, and pause will return an error condition when they are interrupted by an alarm. I have several questions... 1. Are these the only system functions that will not resume where they left off after the interrupt is complete? 2. Is this true on all flavors of UNIX? I recently heard that this is not a problem on System V.
jfh@rpp386.Dallas.TX.US (The Beach Bum) (09/10/88)
In article <373@sdrc.UUCP> gpkinman@sdrc.UUCP (Tim Kinman) writes: >I would like to implement an alarm utility within my application >but I am concerned about the side effects it will have on my existing code. > >It is my understanding that reads from a terminal, wait, and pause will return >an error condition when they are interrupted by an alarm. correct. they return an error (usually -1) and set errno == EINTR. this condition is easily checked for - BUT - must be checked for at every call which could block. >I have several questions... > >1. Are these the only system functions that will not resume where they left off > after the interrupt is complete? functions which will return because of an interrupt will be so documented in the manual. read, write, open, close, ioctl, wait, pause, and many more [ my unix manual by this terminal is snafu'd ... ] the general rule of thumb is I/O on slow devices [ tty's ], any form of wait or pause and any other call which can reasonably be expected to block [ perhaps semwait? ] has the potential to return EINTR. >2. Is this true on all flavors of UNIX? I recently heard that this is not a > problem on System V. i don't know of a UNIX(tm) variant which it is not a problem with. the solution is fairly portable across all unix systems since Way Back When(tm). for example, here is a wait(2) which handles error returns: #include <errno.h> extern int errno; int w_wait (status) int *status; { int i; while ((i = wait (status)) == -1) if (errno != EINTR) return (-1); return i; } this function should be a drop-in replacement for any wait(2) call which you want restarted after an interrupt. i would suggest you add additional features, such as an exit flag to force these calls to exit anyhow before writing missle guidance software using this routine. -- John F. Haugh II (jfh@rpp386.Dallas.TX.US) HASA, "S" Division "If the code and the comments disagree, then both are probably wrong." -- Norm Schryer