Has anyone had any experience with the SIGIO signal? I really can't
seem to find that much documentation on it. (It's not even mentioned in
in the O'Reilly Posix docs.) It seems to me that I ought to get a SIGIO
when any open input fd has data for me.
In the program below, the device '/dev/wwvb1' is softlinked to
/dev/tty00, which has a GPS-driven serial clock attached to it. Output
from this clock occurs at one second intervals. (I have verified this
by doing a 'cat /dev/wwvb1'.) So... if I run this program for five
seconds, I should expect to see an output of 'caught 5 interrupts' --
but it always tells me it caught none. Is there something I'm missing?
-------- snip snip --------
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int fd;
int interrupt_counter=0;
void
sigio_handler(sig)
int sig;
{
interrupt_counter++;
}
static void
exit_handler(void)
{
sigset(SIGIO,SIG_DFL);
printf ("caught %d interrupts\n",interrupt_counter);
exit(0);
}
static void
set_signal(void)
{
int n;
struct sigaction vec;
sigemptyset(&vec.sa_mask);
sigaddset(&vec.sa_mask, SIGIO);
vec.sa_flags = 0;
vec.sa_handler = sigio_handler;
while (1) {
n = sigaction(SIGIO, &vec, NULL);
if (n == -1 && errno == EINTR) continue;
break;
}
if (n == -1) {
perror("sigaction");
exit(1);
}
sigemptyset(&vec.sa_mask);
sigaddset(&vec.sa_mask, SIGINT);
vec.sa_flags = 0;
vec.sa_handler = exit_handler;
n = sigaction(SIGINT,&vec,NULL);
if (n == -1)
{
perror("sigaction(2)");
exit(1);
}
}
main()
{
fd = open ("/dev/wwvb1",O_RDONLY|O_NONBLOCK);
if (fd == -1)
{
printf ("unable to open /dev/wwvb1, bye\n");
exit(1);
}
set_signal();
while(1)
{
pause();
}
}
-------- snip, snip --------
--
Robert L. McMillin | Not the voice of Syseca, Inc. | rlm_at_syseca-us.com
Personal: rlm_at_helen.surfcty.com | rlm_at_netcom.com
Received on Tue Apr 29 1997 - 06:15:51 NZST