Article View: comp.unix.programmer
Article #913Re: Hey, what about SIGIO?
From: James Symon
Date: Thu, 27 Sep 1990 14:15
Date: Thu, 27 Sep 1990 14:15
100 lines
2962 bytes
2962 bytes
In article <LUSH.90Sep26102017@athena0.EE.MsState.Edu>, lush@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@radonc.unc.edu
(919) 966-7710
Technical Details
Message-ID:
<16329@thorin.cs.unc.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!emory!mephisto!mcnc!thorin!aesop!symonReferences:
<LUSH.90Sep26102017@athena0.EE.MsState.Edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!emory!mephisto!mcnc!thorin!aesop!symon From: symon@aesop.cs.unc.edu (James Symon) Newsgroups: comp.unix.programmer Subject: Re: Hey, what about SIGIO? Message-ID: <16329@thorin.cs.unc.edu> Date: 27 Sep 90 14:15:26 GMT References: <LUSH.90Sep26102017@athena0.EE.MsState.Edu> Sender: news@thorin.cs.unc.edu Distribution: comp Lines: 100