Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ucbvax!ucbcad!ames!umd5!decuac!felix!zemon From: jpn@genrad.UUCP (John P. Nelson) Newsgroups: comp.unix.ultrix Subject: Re: Question(s) about process communications Message-ID: <16510@felix.UUCP> Date: 16 Dec 87 22:04:53 GMT Sender: zemon@felix.UUCP Reply-To: jpn@genrad.UUCP (John P. Nelson) Organization: GenRad, Inc., Concord, Mass. Lines: 34 Approved: zemon@felix.UUCP In-Reply-To: <15180@felix.UUCP> Reply-Path: > 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. I'm afraid that you are out of luck. The stdio package buffers output to a pipe by default. There is nothing you can do to change this behavior in an arbitrary child task. You should consider setting up a PSUEDO terminal (see 4 pty) for the child program instead. The PTY looks just like a regular tty to the child task, so that normal line-oriented buffering occurs. (also the child won't block on read, if it attempts to read an entire buffer, when a single line of data is available). The biggest flaw in using PTYs is that there is no equivalent facility in System V systems. However, you said that you were most interested in ULTRIX (BSD) type systems. To set up a pty connection, you must search through all pty pairs, attempting to open up (read/write) a master/slave pair. If either open fails, go to the next pty. When a pair has been successfully opened, you can set up the tty mode on the slave pair (it is just like a tty, see tty(4)). You should also set up the master mode (input as either raw data, or each packet prefixed with a #chars byte). Then after fork()ing, in the child task close the master side, dup2 the slave descriptor into 0 1 and 2. Then exec. The child task will function normally. Good Luck. I'd send you some sample code, but it is derived from the "script" program source, and I don't want to violate my source license. ------- End of Forwarded Message