#include "socketfun.h" #include #include #include #include int main() { int p[2]; int fd; int dummy; if (pipe(p) == -1) exit(1); if (fork() != 0) { if (fork() != 0) { /* This is the parent, a.out process. */ close(p[0]); /* Simply close the pipe and wait for the children to exit. */ close(p[1]); wait(&dummy); wait(&dummy); exit(0); } fd = open("f1.txt", O_RDONLY); /* This is the bin/x child. First redirect stdin */ if (fd < 0) exit(1); dup2(fd, 0); close(fd); dup2(p[1], 1); /* Then stdout, exec and exit if there was an error. */ close(p[0]); close(p[1]); execlp("/bin/x", "x", "4.5", NULL); exit(1); } fd = request_connection("eecs.utk.edu", 6000); /* And the bin/y child - do stdout. */ dup2(fd, 1); close(fd); dup2(p[0], 0); /* Then stdin, exec and exit. */ close(p[0]); close(p[1]); execlp("/bin/y", "y", "fred", "5", NULL); exit(1); }