Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I disagree with Nathan Fellman - the other question is not a duplicate of this, though the subject is related.</p> <p>For simple unidirectional communication, popen() is a decent solution. It is no use for bi-directional communication, though.</p> <p>IMO, imjorge (Jorge Ferreira) gave most of the answer (80%?) for bi-directional communication - but omitted a few key details.</p> <ol> <li>It is crucial that the parent process close the read end of the pipe that is used to send messages to the child process.</li> <li>It is crucial that the child process close the write end of the pipe that is used to send messages to the child process.</li> <li>It is crucial that the parent process close the write end of the pipe that is used to send messages to the parent process.</li> <li>It is crucial that the child process close the read end of the pipe that is used to send messages to the parent process.</li> </ol> <p>If you do not close the unused ends of the pipes, you do not get sensible behaviour when one of the programs terminates; for example, the child might be reading from its standard input, but unless the write end of the pipe is closed in the child, it will never get EOF (zero bytes from read) because it still has the pipe open and the system thinks it might sometime get around to writing to that pipe, even though it is currently hung waiting for something to read from it.</p> <p>The writing processes should consider whether to handle the SIGPIPE signal that is given when you write on a pipe where there is no reading process.</p> <p>You have to be aware of pipe capacity (platform dependent, and might be as little as 4KB) and design the programs to avoid deadlock.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload