open() and pipes

Peter Corlett abuse at cabal.org.uk
Wed Aug 2 17:16:04 BST 2006


On 2 Aug 2006, at 16:57, Uri Guttman wrote:
[...]
> socketpair and pipe are the same call internally on most/all modern
> unixes these days. both create 2 handles for the parent/child for use
> after forking. and they don't have any way to attach directly to a
> process, that is done by the fork/exec calls. all that is done for you
> in ipc::open2/3 which is why that module is there. the problem is  
> solved
> already, you just need to code so there is no io deadlock or use async
> io which won't block. nuff said.

The syscall might well be the same, but it's what's exposed at the  
libc and Perl layers that's really of interest here.

IPC::Open2 opens two pipes, one in each direction[0] whereas a  
socketpair would allow it to be done with one filehandle. Sometimes a  
socketpair is what you really need, so it's a bit of a shame that  
Perl doesn't let you have them easily.

I suspect that implementing David Cantrell's open(FOO, "|program|")  
in terms of socketpair wouldn't actually be that hard. Getting the  
patch accepted might be more interesting though :)


[0] It actually opens *three* because it wraps IPC::Open3




More information about the london.pm mailing list