🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.unix.programmer
6 messages
6 total messages Started by Edward Luke Wed, 26 Sep 1990 15:20
Hey, what about SIGIO?
#905
Author: Edward Luke
Date: Wed, 26 Sep 1990 15:20
16 lines
1139 bytes
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?

Edward Luke
Mississippi State University
NSF Engineering Research Center for Complex Field Simulations
Re: Hey, what about SIGIO?
#885
Author: Jonathan I. Kamens
Date: Wed, 26 Sep 1990 18:44
30 lines
2110 bytes
In article <LUSH.90Sep26102017@athena0.EE.MsState.Edu>, lush@EE.MsState.Edu (Edward Luke) writes:
|> 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?

  See the man page fcntl(2).  You want to use the F_SETOWN fcntl call on the
file descriptor and set the ownership to your PID, and then use the FASYNC
fcntl to turn on asynchronous I/O; when ASYNC is enabled, and input comes in
on the file descriptor, your process will get SIGIO.

  I'm not certain that you'll get SIGIO if there is room for writing in a
pipe; I've never used it for that, and fcntl(2) only mentions data waiting to
be read when it mentions FASYNC, so I don't know whether or not it'll work.

  Oh, you'll also get SIGURG when there is an "urgent condition" on a socket;
I'm not completely sure what an "urgent condition" is, perhaps that's what
they call a premature closing of the other end of the socket or something.

  One more thing -- I believe that if the other end of the FD is closed,
you'll get a SIGIO, and then when you read, you'll get 0 bytes, thus
signalling EOF.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710
Re: Hey, what about SIGIO?
#913
Author: James Symon
Date: Thu, 27 Sep 1990 14:15
100 lines
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
Re: Hey, what about SIGIO?
#916
Author: Tony Rems
Date: Thu, 27 Sep 1990 23:19
29 lines
1446 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?
>

Try the select(2) system call on BSD or SVR4 or the poll(2) system
call on any SVR3 or greater and this should do what you want.

-Tony


-----------------------------------------------------

Somedays, it doesn't pay to get out of bed.

NOTE: My opinions are barely my own much less 
my employers'.

-----------------------------------------------------
Re: Hey, what about SIGIO?
#920
Author: Joel Clark
Date: Fri, 28 Sep 1990 00:51
37 lines
1883 bytes
In article <1990Sep26.184409.10155@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes:
>In article <LUSH.90Sep26102017@athena0.EE.MsState.Edu>, lush@EE.MsState.Edu (Edward Luke) writes:
>|> 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()
>|> Just what is the SIGIO signal for?
>
>  See the man page fcntl(2).  You want to use the F_SETOWN fcntl call on the
>.....
>  Oh, you'll also get SIGURG when there is an "urgent condition" on a socket;
						^^^^^^^^^^^^^^^^
>I'm not completely sure what an "urgent condition" is, perhaps that's what
>they call a premature closing of the other end of the socket or something.
>-- 
>Jonathan Kamens			              USnail:
>MIT Project Athena				11 Ashford Terrace
>jik@Athena.MIT.EDU				Allston, MA  02134
>Office: 617-253-8495			      Home: 617-782-0710


An "urgent condition" is when Out Of Band data arrives.  This is data
sent with the MSG_OOB flag set. i.e. "send(fd,buf,buflen,MSG_OOB)"
This is generally used to send signals such as interrupt when a DEL
key is hit.  Thus the receiving process can handle the SIGURG signal
by reading and tossing all the data in the socket upto the MSG_OOB
data if this is what it needs to do.

Joel Clark
Intel Scientific Computers
joel@isc.intel.com






line fodder
Re: Hey, what about SIGIO?
#921
Author: Jonathan I. Kamens
Date: Fri, 28 Sep 1990 03:50
104 lines
3330 bytes
In article <16329@thorin.cs.unc.edu>, symon@aesop.cs.unc.edu (James Symon) writes:
|> 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().

  Your program doesn't work for me unless I add the fcntl I mentioned in my
last message.  In particular, if I compile the program at the end of this
message without DO_ASYNC defined, then it doesn't detect input, but if I
compile it with DO_ASYNC defined, then it does.

  Just because it works without the fcntl on your system, doesn't mean you
should expect it to work that way on other systems.

  Note, too, that if you do the fcntl once on your tty and then forget to turn
it off, the next time you run a program that tries to use SIGIO, it'll work
even if it doesn't do the fcntl, since the FASYNC will stay in effect on the
tty line.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710

------------------------------------------------------------------

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

#ifdef DO_ASYNC
int ttyflags;
#endif

void
handler(signal)
int signal;
{
     printf("Got some input.\n");
}

void
inthandler(signal)
int signal;
{
     if (signal)
	  printf("Got an interrupt.\n");
     
#ifdef DO_ASYNC
     if (fcntl(fileno(stdin), F_SETFL, ttyflags & ~FASYNC) < 0) {
	  perror("Couldn't set tty flags");
	  exit(1);
     }
#endif

     exit(0);
}

main()
{
        extern void handler();
        int ndx, smask, oldmask;
        struct sigvec holder;
	
#ifdef DO_ASYNC
	if ((ttyflags = fcntl(fileno(stdin), F_GETFL, 0)) < 0) {
	     perror("Couldn't get tty flags");
	     exit(1);
	}

	if (fcntl(fileno(stdin), F_SETFL, ttyflags | FASYNC) < 0) {
	     perror("Couldn't set tty flags");
	     exit(1);
	}
#endif
	     
        holder.sv_handler = (int(*)()) handler;
        holder.sv_mask = 0;
        holder.sv_flags = 0;

        sigvec(SIGIO,&holder,0);

	holder.sv_handler = (int(*)()) inthandler;
	holder.sv_mask = 0;
	holder.sv_flags = 0;

	sigvec(SIGINT, &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);
                }

	inthandler(0); /* to turn off strange modes */
	
	exit(0);
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads