From owner-freebsd-questions@FreeBSD.ORG Thu May 29 15:44:15 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4AB7D37B401 for ; Thu, 29 May 2003 15:44:15 -0700 (PDT) Received: from adsl-64-161-78-226.dsl.lsan03.pacbell.net (adsl-64-161-78-226.dsl.lsan03.pacbell.net [64.161.78.226]) by mx1.FreeBSD.org (Postfix) with SMTP id 4922143FA3 for ; Thu, 29 May 2003 15:44:14 -0700 (PDT) (envelope-from oremanj@adsl-64-161-78-226.dsl.lsan03.pacbell.net) Received: (qmail 83150 invoked by uid 1001); 29 May 2003 22:45:44 -0000 Date: Thu, 29 May 2003 15:45:44 -0700 From: Joshua Oreman To: Gabriel Ambuehl Message-ID: <20030529224544.GC82918@webserver.get-linux.org> References: <77243311093.20030529190121@buz.ch> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <77243311093.20030529190121@buz.ch> User-Agent: Mutt/1.4i cc: questions@freebsd.org Subject: Re: portable coproccesses, openpty, forkpty? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 May 2003 22:44:15 -0000 On Thu, May 29, 2003 at 07:01:21PM +0200 or thereabouts, Gabriel Ambuehl seemed to write: > Hi, > ok maybe I'm offtopic here, if so please excuse me ;-). > > I need to implement a coprocess feature (a.stdin gets fed to b.stdin > and b.stdout becomes a.stdin, so basically replacing stdin with > a processed version thereof). Now the most obvious approach would be > to use pipes to redirect stdin/stdout of the two processes but > unfortunately, Stevens' Advanced Programming in the UNIX environment > notes that this will result in deadlocks if stdio is used. And as I > tend to trust Stevens on such issues, I went looking further in the > book and he says the only way to do totally transparent coprocesses is > with ptys. > > Now as I understand it, BSD and SysV use different syntax to get ptys > and so I'm wondering how to implement coprocesses in a portable way (on > FreeBSD, it seems easy, forkpty does most of the work I need it to do > but is it portable? Doesn't seem to be POSIX). > > > I'd appreciate any comments, pointers, RTFM's, code snippets, whatever. Yep, forkpty()/openpty() is definitely not POSIX. (Under FBSD, you have to #include and link with -lutil to use it.) However, the source code of forkpty() and openpty() is in /usr/src/lib/libutil/pty.c, and you could put that file in your program's directory, and link with a simplified version of that (but you might have to change the function names). Then you would be portable (hopefully :-) -- Josh > > > TIA & regards, > Gabriel > > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"