#include #include #include #include "sockettome.h" main() { int s, fd, dummy; int p[2]; s = serve_socket(9020); fd = accept_connection(s); pipe(p); if (fork() == 0) { dup2(fd, 0); dup2(p[1], 1); close(p[0]); close(p[1]); close(fd); execlp("kim", "kim", NULL); exit(1); } close(p[1]); /* No reason to keep p[1] around any more */ if (fork() == 0) { dup2(p[0], 0); dup2(fd, 1); close(p[1]); close(fd); execlp("khloe", "khloe", NULL); exit(1); } (void) wait(&dummy); /* Wait for khloe. If it's Kim, Khloe's dying pretty soon so don't worry about it. That wouldn't be true had you not closed p[1]. */ if (fork() == 0) { dup2(p[0], 0); dup2(fd, 1); close(p[1]); close(fd); execlp("kourtney", "kourtney", NULL); exit(1); } close(fd); close(p[0]); (void) wait(&dummy); (void) wait(&dummy); exit(0); }