kevin
I got great help from a lot of you and I really appreciate it. What
I understand now is that the timeout that I am giving select is the
absolute longest time it will check for date. If some signal happens
the select() could fail and cut the timeout short. Not a problem, I
can work with it.
Thanks,
Kevin
Glynn Clements (gl...@sensei.co.uk) wrote:
: Kevin J. Osowski wrote:
: > Does anyone know what this means?
: It means that a signal arrived while select() was waiting, and
: interrupted it, causing select() to return -1 and set errno to EINTR.
: > I mean short of the works, how can
: > this happen and what do I do when I receive this error. What state am
: > I in. Can I select() again?
: Yes.
: --
: Glynn Clements <gl...@sensei.co.uk>
> Thanks,
>
> I got great help from a lot of you and I really appreciate it. What
> I understand now is that the timeout that I am giving select is the
> absolute longest time it will check for date. If some signal happens
> the select() could fail and cut the timeout short. Not a problem, I
> can work with it.
You can avoid that when you setup the signal handlers with
sigaction() and set the SA_RESTART flag bit. Then these signals won't interrupt it
(you could block the others with sigsetmask() if you want)
-Andi
I just thought I'd point out that using SA_RESTART isn't as portable
as doing the restarting yourself. Keeping this sort of thing in mind
helps you write Unix software as opposed to Linux software.
--
Doug DeJulio | mailto:d...@hks.net
HKS, Incorporated | http://www.hks.net/
Hmm? SA_RESTART is defined by POSIX and Unix95/98. I doubt that you can
find any Unix or Unix like system delivered in the last few years that
won't support it.
On older BSD systems (or Linux with -lbsd) signal() defaults to SA_RESTART.
I think POSIX.1 is to use as the minimal common subset for portable Unix
programs.
Or do you write C in K&R C instead of ISO/ANSI C89 too?
-Andi
No, SA_RESTART is not defined by POSIX.1.
It's defined by SVR4 and 4.3+BSD, so it's fairly common, but it's not
part of POSIX.1. Further, whether a given system's default is to
restart system calls or not isn't defined by POSIX.
(Source: "Advanced Programming in the UNIX Environment", by Stevens,
pages 277 and 297.)
Actually, with select(), SA_RESTART won't help. Select will _always_
cause an EINTR even with re-startable signals if you have a signal
handler..
Why? BSD behaviour. And BSD is where both select() and restartable
system calls came from.
(Linux doesn't guarantee the same sort of restartability as BSD, but we
try to have a "least surprises" kind of behaviour. POSIX specifies that
some systems may have ways of making system calls restartable, but also
specifies that behaviour is not defined or uniform..).
Linus
Stevens got this wrong. The Posix.1 book put out by the IEEE ~1991
definitely specified the behavior of SA_RESTART.
I believe the book I am remembering is:
"Information Technology-Portable Operating System Interface (Posix :
Part 1 : System Application Program Interface)"
Technical Committee on Operating Systems and Operational Environments;
Paperback;
(Unfortunately it is apparently out of print. Or has it been superceded
by a new book?)
In any event HP-UX, AIX, Solaris, Linux, SYSVR4 and *BSD all implement
it.
-Rob