generate EOF on socketpair?

Robert Potter rpotter at grip.cis.upenn.edu
Mon Apr 1 07:52:26 AEST 1991


I am trying to write a replacement for popen() that returns a socket for
two-way communication with some program's standard I/O.  My implementation is
along these lines:

int process_open(...)
{
    int sock[2];

    socketpair(AF_UNIX, SOCK_STREAM, 0, sock);
    if (vfork() == 0) {		/* are we the child? */
	dup2(sock[0], 0);
	dup2(sock[0], 1);
	execv(...);
    }
    return sock[1];
}

My problem:  how do I indicate to the program that it has reached EOF on its
standard input?  I can't just close the socket, since I want to keep the socket
open for reading.  Do I have to set up two separate sockets (or pipes)?

	-Robert



More information about the Comp.unix.programmer mailing list