Hey, what about SIGIO?

James Symon symon at aesop.cs.unc.edu
Fri Sep 28 00:15:26 AEST 1990


In article <LUSH.90Sep26102017 at athena0.EE.MsState.Edu>, lush at EE.MsState.Edu (Edward Luke) writes:
> 
> In signal.h there is a signal defined as:
> #define        SIGIO   23      /* input/output possible signal */
> 
> 
> I have an application that will be doing computations, asynchronously
> with this I would like to get a signal when new data arrives on an
> input file descriptor, or when an output file descriptor is free to be
> filled again.  Is it possible for me to do this without using fork()
> to start another process to monitor the file descriptor?  Can I tell
> the OS to give me a SIGIO when there is a pending condition on a
> socket?  Just what is the SIGIO signal for?
> 


Here are some little test programs I wrote using standard input (the
keyboard) to learn how to do signal trapping. I don't think you need
to mess with fcntl().

****************************************

#include <stdio.h>
#include <signal.h>

int done = 0;

void
handler(signal)
int signal;
{

        if(signal != SIGIO)
                {
                printf("caught signal other than SIGIO . . . wrong!");
                exit(1);
                }
        else
                {
                printf("I lied. I'm taking a nap. You'll have to wait.\n");
                done = 1;
                }
}

main()
{
        extern void handler();
        int ndx;

        signal(SIGIO,handler);
        while(!done)
                {
                printf("I'll do some work here while I wait for your <CR>.\n");
                sleep(5);
                }
}


*************	Here's another:	*************


#include <stdio.h>
#include <signal.h>

void
handler(signal)
int signal;
{
}

main()
{
        extern void handler();
        int ndx, smask, oldmask;
        struct sigvec holder;

        holder.sv_handler = handler;
        holder.sv_mask = 0;
        holder.sv_flags = 0;

        sigvec(SIGIO,&holder,0);

        smask = sigmask(SIGIO);

        for(ndx=0; ndx < 4; ndx++)
                {
                oldmask = sigblock(smask);
                printf("smask = %x, oldmask = %x, wait, I'm working . . .\n",smask,oldmask);
                sleep(1);
                printf("Well? Hit return.\n");
                sigpause(oldmask);
                sigsetmask(oldmask);
                }
}

****************************************************

Jim Symon
symon at radonc.unc.edu
(919) 966-7710



More information about the Comp.unix.programmer mailing list