famzah / popen-noshell

A much faster popen() and system() implementation for Linux
68 stars 13 forks source link

make popen_noshell optionall produce bidirectional pipes #5

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Not an "issue" in the classical sense, but I was searching for an 
implementation of popen that does not use fork (since pthread_atfork does nasty 
things here with some libraries), and that is bidirectional (I want to 
"control" some child process).

It looks like it shouldn't be too hard to add a third option to r and w that 
allows for proper bidirectional communication.

Original issue reported on code.google.com by plasma...@gmail.com on 7 Mar 2013 at 9:25

GoogleCodeExporter commented 9 years ago
I'm really sorry for the late reply. It turned out that I wasn't getting any 
notifications for new issues here.

POSIX says that "a pipe is by definition unidirectional". Therefore, what you 
are looking for is not really standard. The usual way for a bidirectional 
communication is to use two separate pipes -- one for output and one for input. 
This is well explained at the following page: 
http://stackoverflow.com/questions/3884103/can-popen-make-bidirectional-pipes-li
ke-pipe-fork

There are no problems to integrate this with the popen_noshell() library. You 
can use it to clone() a child without invoking fork() and then do all the 
standard stuff yourself (like redirecting pipes, etc).

I've done a quick example for you to review. It's attached to this ticket.

Original comment by ivan.zah...@gmail.com on 24 May 2013 at 1:10

Attachments: