on Thu, Feb 07, 2002 at 11:02:44AM +0000, david casal wrote:
The data stream needs to be continuous. One is a simulation package (swarm.org), the other a visual programming music thing (pure-data.org). I need consistent data out of PD, into swarm, out of swarm and back to PD.
man socketpair
just treat the resulting file descriptors like they came from pipe(2) except they're bi-directional. Most *nix only implement socketpair in the unix domain. The unix(7) man page has details.
If you dup2 one of the resulting descriptors onto the stdin,stdout and stderr of each process then exec them, they should talk happily. eg: (this ommits error handling)
int fds[2], x;
socketpair(PF_UNIX, SOCK_STREAM, 0, fds); switch(fork()) { case -1: err(1, "fork");
case 0: for (x = 0; x < 3; x++) dup2(fds[0], x); close(fds[0]); close(fds[1]); execlp("swarm", ...blah...); _exit(0); default: for (x = 0; x < 3; x++) dup2(fds[1], x); close(fds[0]); close(fds[1]); execlp("pd", ... blah...); break; }
(it's still before 12, there are likely mistakes in this) It is possible to do it with pipe(2), but it uses twice as many file descriptors. If all doesn't seem right, don't dup2 stderr (fd 2) for each process and see what happens.