Gnu c/c++: Alarm and read issue in linux

Andres Heinloo
Wed Apr 7 13:56:00 GMT 2004


> My questions are:
> 1. Should alarm() work with a system call like read()?

Yes, the signal handler should execute. After that the call should either
continue or break with errno=EINTR (I don't remember what was the
behaviour of signal() on Linux---better use sigaction() in which case you
can control this behaviour).

However, it only works if the driver cooperates properly with the kernel.

> 2. If not, is there any work-around?

Non-blocking I/O, asynchronous I/O, select(), but, again, they must be
supported by the driver.

If nothing else works, you can read the device in a subprocess and send 
the data to the main process via pipe (alarm() definitely works when you 
read() a pipe) or use threads.


More information about the Gcc-help mailing list