[erlang-questions] Issues with stdin on ports

Richard A. O'Keefe ok@REDACTED
Wed Jul 31 03:51:06 CEST 2013

I think we may be approaching clarity here.

Whether the pipes in your underlying UNIX are bidirectional
or not, whether your popen() supports a "r+" argument or not,
bidirectional pipe-based communication between a parent
process and a child process is safe *IF*

(1) the child process first reads all the data without writing
    and some time after receiving EOF writes all its results
    without reading, *OR*

(2) both programs have been specially written to communicate
    in this way, possibly using asynchronous I/O, non-blocking
    I/O, or multiple threads in some way, *AND*
    they are aware of the value of PIPE_BUF that applies to
    the system they are running on.

(3) pipes let you report end-of-file by closing them, but no
    other signal.  In order to signal a program at the other
    end of a pipe, you need to know the process ID of the
    process, which for the equivalent of popen("foobar",...)
    is not trivially found.

(4) To send attention signals of some sort, you need to use

Per Hedeland wrote: "Erlang open_port/2 *by default* creates
a bi-directional, deadlock-free communication channel to the
external process."  That's still not quite right.  The thing
that governs whether a deadlock is possible or not is the
*protocol* the communicating processes use.  And it is still
the case that an Erlang process may be deadlocked this way;
it's just that the whole Erlang system won't be tied up if it

More information about the erlang-questions mailing list