From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20120 invoked by alias); 6 Apr 2004 16:02:34 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 19973 invoked from network); 6 Apr 2004 16:02:26 -0000 Received: from unknown (HELO host11.oneononeinternet.com) (209.239.43.35) by sources.redhat.com with SMTP; 6 Apr 2004 16:02:26 -0000 Received: from solarwave (pool-151-203-236-217.bos.east.verizon.net [151.203.236.217]) by host11.oneononeinternet.com (8.12.10/8.12.10) with ESMTP id i36G2PCH018137 for ; Tue, 6 Apr 2004 12:02:25 -0400 From: "Mark Richards" To: Subject: Gnu c/c++: Alarm and read issue in linux Date: Tue, 06 Apr 2004 16:02:00 -0000 Message-ID: <008a01c41bf0$8e72dd90$7101a8c0@solarwave> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-SW-Source: 2004-04/txt/msg00067.txt.bz2 Gnu c/c++: Alarm and read issue in linux I'll start out by saying how enormously helpful this list has been to me. As still very much a beginner with Gnu C and tacking an embedded project, I'm stretched a bit, but enjoying every minute of it. I may also be doing some stupids, so please call them as you see them. I'm writing for an embedded system which uses the 2.2.5-15 linux kernel. The code is being developed in RedHat 6.2 using egcs-2.91.66 (gnu c/c++). Everything is working just fine - except for my implimentation of a certain signal, called SIGALRM. The signal system is, according to my understanding, the Linux way of providing software interrupts. In the project I'm working on, a press of a button (there are two in the embedded unit) is handled by a button device driver.=20 The driver is initialized by: int buttonFd =3D open ("/dev/button", O_RDWR); Then the signal handler is setup: volatile sig_atomic_t event_trigger =3D 1; void catch_alarm (int sig) { cout << "Alarm event triggered" << endl; event_trigger =3D 0; signal (SIGALRM, int sig); } // this call sets up the connection between the alarm signal // and the function catch_alarm signal (SIGALRM, catch_alarm); The code then enters a read() call which seems to hang (or block) the signal. At the expected alarm timeout, nothing happens. The following code below is in a second source file, so to connect back to both the variable "event_trigger" and the function "catch_alarm", i am declaring these: extern volatile sig_atomic_t event_trigger; extern void catch_alarm(int sig); Here's the code that does the read(): alarm(10); read (buttonFd, &c, 1);=20 I tried initializing the driver using: int buttonFd =3D open ("/dev/button", O_RDWR | O_NONBLOCK); but this had no effect. Unfortunately I don't have the driver code, otherwise I think it might be possible to set it up as a non-blocking driver.=20 My questions are: 1. Should alarm() work with a system call like read()? 2. If not, is there any work-around? I've read a bit about waitpid() which seems like it might be an option, but I don't have a good example as to how it could be used in this case. Any and all suggestions will be eagerly heard. Thank you! Mark Richards