Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!husc6!hao!oddjob!mimsy!chris
From: chris@mimsy.UUCP (Chris Torek)
Newsgroups: comp.unix.questions
Subject: Re: Need help with interprocess communications
Message-ID: <9674@mimsy.UUCP>
Date: Tue, 8-Dec-87 04:22:13 EST
Article-I.D.: mimsy.9674
Posted: Tue Dec  8 04:22:13 1987
Date-Received: Sun, 13-Dec-87 09:35:32 EST
References: <8117@steinmetz.steinmetz.UUCP>
Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
Lines: 53
Keywords: Pipes, Ptys, Buffering, I/O

In article <8117@steinmetz.steinmetz.UUCP> lanzo@mercutio.steinmetz
(Mark Lanzo) writes:
>     call "pipe" to open a pipe which is for writing from parent-to-child
>     call "pipe" to open a pipe for writing from child-to-parent

(Using a Unix domain stream socket is more efficient, since one socket
can be used bidirectionally.  Not that this matters...)

>     use fcntl to set FASYNC mode on all descriptors.

(Remember to F_SETOWN it to get the signals sent to the right process
or pgroup.)

>     fork process:
>
>	child				 
>        -------                          
>	disconnect unused ends of pipes:
>	    close parent-to-child write end
>	    close child-to-parent read	end
>	use close/dup etc to make pipe ends be stdin & stdout.

Good so far.

>	set unbuffered I/O mode on stdin, stdout, stderr

This does nothing, because...

>	exec subprocess...

this wipes out the stdio structures you just crafted.  Stdio is
part of the user process, folks, not the kernel; it is not retained
across exec!  There is no way, short of changing the code for the
child, to force child programs to run unbuffered.

>Also:  Is there a way that I can determine WHICH file descriptor caused
>a SIGIO interrupt to be invoked, or by which I can set up a different
>interrupt handler for each descriptor?

No, but rather than using ioctl(FIONREAD), you can use select, which
will tell you everything at once.  In fact, you can then stop using
SIGIO, as long as you are always waiting for input.

>P.s.  I'm also interested in solutions using the pseudoterminal
>mechanism or sockets.

pty's will make child programs think they are talking to terminals
(because they *are*), which makes them behave `interactively'.  Sockets
are the same as pipes, since pipes are in fact just sockets that have
been shut down (see `man 2 shutdown').
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris