home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume11 / musbus / part04 / pipe.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-16  |  534 b   |  27 lines

  1. /*
  2.  *  pipe  -- test single process pipe throughput (no context switching)
  3.  *
  4.  *  $Header: pipe.c,v 3.5 87/06/22 14:32:36 kjmcdonell Beta $
  5.  */
  6.  
  7. main(argc, argv)
  8. int    argc;
  9. char    *argv[];
  10. {
  11.     char    buf[512];
  12.     int    iter = 2048;    /* 1M byte */
  13.     int    pvec[2];
  14.  
  15.     pipe(pvec);
  16.     close(0); dup(pvec[0]); close(pvec[0]);
  17.     close(1); dup(pvec[1]); close(pvec[1]);
  18.  
  19.     while (iter-- > 0) {
  20.         if (write(1, buf, sizeof(buf)) != sizeof(buf))
  21.             perror("write failed");
  22.         if (read(0, buf, sizeof(buf)) != sizeof(buf))
  23.             perror("read failed");
  24.     }
  25.     exit(0);
  26. }
  27.