home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
-
- #include "sys/unix.h"
-
- static void
- copyio (void)
- {
- char buf[512];
- register int n;
-
- while ((n = read (0, buf, 512)) > 0)
- write (1, buf, n);
- }
-
- int
- main ()
- {
- int p[2];
-
- if (pipe (p) < 0)
- {
- perror ("pipe()");
- exit (1);
- }
-
- switch (vfork ())
- {
- case -1:
- perror ("vfork()");
- exit (1);
- break;
- case 0:
- close (p[0]);
- dup2 (p[1], 1);
- close (p[1]);
- copyio ();
- _exit (0);
- break;
- default:
- break;
- }
-
- switch (vfork ())
- {
- case -1:
- perror ("vfork()");
- exit (1);
- break;
- case 0:
- close (p[1]);
- dup2 (p[0], 0);
- close (p[0]);
- copyio ();
- _exit (0);
- break;
- default:
- break;
- }
- return 0;
- }
-