public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Question about bi-directional pipes.
@ 2002-01-08  8:47 Martin Rode
  2002-01-08 11:52 ` Chris Wedgwood
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Rode @ 2002-01-08  8:47 UTC (permalink / raw)
  To: linux-kernel

I was just wondering if it is possible under Linux to use popen in a
bi-directional way? I want to use popen under php and must write _and_
read from and to the pipe. Some guy at the php mailing list stated that
this is possible to do with BSD, he wasn't sure about linux.

If this is a kernel issue and not a glibc one, is there a way to get
popen work bi-directionally under linux? Say I want a 

pipe = popen ('somefile', 'w+');

return a valid pipe. As it is now, popen (at least under php, but I
think this should be the same), does not return a handle for mode 'w+'.
It does return a handle only for modes 'r' and 'w'.

Regards,

;Martin


-- 
Dipl.-Kfm. Martin Rode
martin.rode@programmfabrik.de

Programmfabrik GmbH
Frankfurter Allee 73d
10247 Berlin

http://www.programmfabrik.de/

Fon +49-(0)30-4281-8001
Fax +49-(0)30-4281-8008
Funk +49-(0)163-5321400

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question about bi-directional pipes.
  2002-01-08  8:47 Question about bi-directional pipes Martin Rode
@ 2002-01-08 11:52 ` Chris Wedgwood
  0 siblings, 0 replies; 3+ messages in thread
From: Chris Wedgwood @ 2002-01-08 11:52 UTC (permalink / raw)
  To: Martin Rode; +Cc: linux-kernel

On Tue, Jan 08, 2002 at 09:47:06AM +0100, Martin Rode wrote:

    I was just wondering if it is possible under Linux to use popen in
    a bi-directional way?

using pipe(2) --- no

    I want to use popen under php and must write _and_ read from and
    to the pipe. Some guy at the php mailing list stated that this is
    possible to do with BSD, he wasn't sure about linux.

Some (all) of the *BSD's implement pipe(2) using UNIX domain sockets
under the hood and were thus able to do this, however, I don't believe
any other OS ever did this and I certainly wouldn't assume it will
work for compatibility reasons.

    If this is a kernel issue and not a glibc one, is there a way to
    get popen work bi-directionally under linux? Say I want a

    pipe = popen ('somefile', 'w+');

Don't use glibc for this, it can't do what you want.  I have a small
library I wrote that does a popen type thing and gives separate access
to stdin, stdout and stderr of the process --- if that is of use you
are welcome to it (it's C, not php, I have no idea about how to import
C functions into php).

With a (small) amount of effort, I can even make a version that nukes
stderr and wraps the stdin/stdout functions with a a UNIX domain socket
which will do pretty much exactly what you want[1].


  --cw

[1] Oh, it doesn't do command-line parsing as I explicitly didn't want
    this when I wrote it.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question about bi-directional pipes.
@ 2002-01-08 15:23 Jesse Pollard
  0 siblings, 0 replies; 3+ messages in thread
From: Jesse Pollard @ 2002-01-08 15:23 UTC (permalink / raw)
  To: Martin.Rode, linux-kernel

---------  Received message begins Here  ---------

> 
> I was just wondering if it is possible under Linux to use popen in a
> bi-directional way? I want to use popen under php and must write _and_
> read from and to the pipe. Some guy at the php mailing list stated that
> this is possible to do with BSD, he wasn't sure about linux.
> 
> If this is a kernel issue and not a glibc one, is there a way to get
> popen work bi-directionally under linux? Say I want a 
> 
> pipe = popen ('somefile', 'w+');
> 
> return a valid pipe. As it is now, popen (at least under php, but I
> think this should be the same), does not return a handle for mode 'w+'.
> It does return a handle only for modes 'r' and 'w'.
> 
> Regards,

It is a convention used to reduce the risk of deadlock between the two
processes. If you are reading from a fd, you can't be writing to the
other (the pipe syscall returns two fds). If both processes attempt read
simultaneously, both sleep forever (unless using select/poll with a timeout).

Pipes were designed for creating one-way communication paths between processes.

It is better to use a domain socket which has better semantics for just
this occurance. Then you can use the accept/send/recv... network functions
which are much better at bi-directional communication.

-------------------------------------------------------------------------
Jesse I Pollard, II
Email: pollard@navo.hpc.mil

Any opinions expressed are solely my own.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-01-08 15:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-01-08  8:47 Question about bi-directional pipes Martin Rode
2002-01-08 11:52 ` Chris Wedgwood
  -- strict thread matches above, loose matches on Subject: below --
2002-01-08 15:23 Jesse Pollard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox