View previous topic :: View next topic |
Author |
Message |
geta Apprentice
Joined: 10 May 2003 Posts: 153
|
Posted: Wed Sep 17, 2003 9:58 pm Post subject: signal handling and glibc |
|
|
--------------------
UPDATE: By including some output messages I've rooted the problem down to wrong file flags, which locked up read() in my sigio handler. Although I set the O_NONBLOCK attribute I didn't set it in a clean fashion. So my questions from earlier on are solved.
But there has been an other question popping up. Why does Linux keep sending a few dozen of SIGIOs per second, although there's no input at any of the opened ports?
--------------------
Being a newbie at implementing (programming) inter-process features, I've got some problems related to signal handling, which neither the glibc-manual nor google could give me any answers to.
Here's my programme. It opens one real serial port (/dev/ttySx) and a terminal (/dev/pts/x). As soon as input arrives (signalled by a SIGIO) it reads out both ports (it cannot distiguish, which port sent the signal), displays the content and sends the content on to the other port.
Code: | #include <stdio.h> // printf, scanf
#include <termios.h> // needed for termios struct
#include <unistd.h> // needed for termios struct and getpid()
#include <fcntl.h> // needed by open(,,) and for I/O modes (sigio)
#include <stdlib.h> // needed by close()
#include <string.h>
#include <signal.h> // IPC signals
#include <sys/types.h> // to get PID of this process |
some variables, then define signal handlers:
Code: | void term_handler(int sig){...}
void sigint_handler(int sig){...}
void port_handler(int sig){...//print data and copy to other port} |
then cleanup(), then main:
Code: | int main (){
atexit(cleanup);
signal(SIGIO, port_handler);
signal(SIGTERM, term_handler);
signal(SIGINT, sigint_handler); | ... then set up pty and ttySx to send SIGIOs to this process...
and now the important bit:
Code: | sigset_t waitmask;
sigemptyset(&waitmask);
sigaddset(&waitmask, SIGIO);
// sigaddset(&waitmask, SIGTERM);
// sigaddset(&waitmask, SIGINT);
while(1){
sigsuspend(&waitmask); // pause as long as no signals or interrupts appear
} // use SIGINT or SIGTERM to properly shutdown programme | other functions etc...
What strikes me, is that, although setting up the signal handlers it did not react at all, when I had pause() instead of sigsuspend() in the endless-loop.
Furthermore I can only shut down the programme with ctrl-c when "waitmask" is set exactly as above, although the SIGTERM and SIGINT are those signals, which I've implemented for that purpose. Does the programme think that I've sent it a SIGIO when I enter ctrl-c?
I'd be glad if anyone could answer my questions and give some explanations as to why those strange(?) things happen.
My environment: glibc 2.3.2-r1, anjuta (but testing done outside of anjuta because of the silly gnome-pty-helper, which blocks those crucial signals), xterm
Cheers, geta
Last edited by geta on Thu Sep 18, 2003 11:10 am; edited 1 time in total |
|
Back to top |
|
|
puggy Bodhisattva
Joined: 28 Feb 2003 Posts: 1992 Location: Oxford, UK
|
Posted: Wed Sep 17, 2003 10:03 pm Post subject: |
|
|
Request for programming help so... Moving to Portage & Programming from Off The Wall.
Puggy _________________ Where there's open source , there's a way. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|