Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!rochester!ritcv!cci632!ccicpg!felix!chuck From: chuck@felix.UUCP Newsgroups: comp.unix.ultrix Subject: Question(s) about process communications Message-ID: <15180@felix.UUCP> Date: Wed, 2-Dec-87 20:14:31 EST Article-I.D.: felix.15180 Posted: Wed Dec 2 20:14:31 1987 Date-Received: Sun, 6-Dec-87 20:37:57 EST Sender: chuck@felix.UUCP Reply-To: lanzo@mercutio.UUCP (Mark Lanzo) Organization: General Electric CRD, Schenectady, NY Lines: 57 Approved: zemon@felix.UUCP Reply-Path: Hi, I'm working on an application where I need to be able to have bidirectional communications between two processes, usually a parent & child process. My first attempt at this involved calling "pipe" twice to open a pair of channels, and forking off the subprocess with the pipes connected to its stdin & stdout: pipe(parent_to_child) pipe(child_to_parent) fork() parent process closes read end of "parent_to_child" pipe, and write end of "child_to_parent" pipe; child process does the reverse. Child process uses "dup" or "dup2" to attach the pipes as stdin (file descriptor 0) and stdout (fd 1). exec(subprocess info....) So far, things seem to work, and there is some sort of communications going on between the processes. The problem I run into now is with the buffering mechanisms. Each time the child writes to the parent, I want the parent process to recognize the fact, and fetch the data written. I do NOT want data buffered. This is not a problem to me from the parent end since I can call fflush(), but I don't necessarily have access to the child process source code, so I can't modify its normal activities (such as to insert fflush after every write(), printf(), etc.). The parent process here is the application I'm working on, the child process(es) is any arbitrary executable. The questions then are: Can I determine when the child has written something to the pipe? Can I determine exactly how many characters have been written? Can I do this both in a synchronous and an asynch. fashion? Oh yes, if the answer to any of these is "yes", next comes "How?" :-) I did try using "setbuf" to set non-buffered I/O on stdin and stdout; in the child process, but this didn't seem to have any effect. I would like to find a solution which will work with different flavors of Unix too (Ultrix, BSD, SysV), but the only one which I have real familiarity with is Ultrix, so I'm afraid I don't know what is portable and what isn't. I am aware of the existence of "sockets", but don't know how to use them, and what little SysV documentation I could find never mentioned them at all, so I don't know if these are particularly portable. It would also be useful to me to communicate between two processes which aren't directly related (one the parent of the other); so far, the only mechanism I know of which might be useful here (besides sockets) is the pseudoterminal drivers (pty/tty). Can anyone out there enlighten me? Thanks in advance, Mark mercutio!lanzo