xref: /minix3/minix/tests/test13.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc /* test 13 */
2*433d6423SLionel Sambuc 
3*433d6423SLionel Sambuc /* File: pipes.c - created by Marty Leisner */
4*433d6423SLionel Sambuc /* Leisner.Henr         1-Dec-87  8:55:04 */
5*433d6423SLionel Sambuc 
6*433d6423SLionel Sambuc /* Copyright (C) 1987 by Martin Leisner. All rights reserved. */
7*433d6423SLionel Sambuc /* Used by permission. */
8*433d6423SLionel Sambuc 
9*433d6423SLionel Sambuc #include <sys/types.h>
10*433d6423SLionel Sambuc #include <sys/wait.h>
11*433d6423SLionel Sambuc #include <stdlib.h>
12*433d6423SLionel Sambuc #include <unistd.h>
13*433d6423SLionel Sambuc #include <stdio.h>
14*433d6423SLionel Sambuc 
15*433d6423SLionel Sambuc #define BLOCK_SIZE 	1000
16*433d6423SLionel Sambuc #define NUM_BLOCKS	1000
17*433d6423SLionel Sambuc 
18*433d6423SLionel Sambuc char buffer[BLOCK_SIZE];
19*433d6423SLionel Sambuc 
20*433d6423SLionel Sambuc int max_error = 2;
21*433d6423SLionel Sambuc #include "common.h"
22*433d6423SLionel Sambuc 
23*433d6423SLionel Sambuc 
24*433d6423SLionel Sambuc int main(void);
25*433d6423SLionel Sambuc void quit(void);
26*433d6423SLionel Sambuc 
main()27*433d6423SLionel Sambuc int main()
28*433d6423SLionel Sambuc {
29*433d6423SLionel Sambuc   int stat_loc, pipefd[2];
30*433d6423SLionel Sambuc   register int i;
31*433d6423SLionel Sambuc 
32*433d6423SLionel Sambuc   start(13);
33*433d6423SLionel Sambuc 
34*433d6423SLionel Sambuc   pipe(pipefd);
35*433d6423SLionel Sambuc 
36*433d6423SLionel Sambuc   switch (fork()) {
37*433d6423SLionel Sambuc       case 0:
38*433d6423SLionel Sambuc 	/* Child code */
39*433d6423SLionel Sambuc 	for (i = 0; i < NUM_BLOCKS; i++)
40*433d6423SLionel Sambuc 	         if (read(pipefd[0], buffer, BLOCK_SIZE) != BLOCK_SIZE) break;
41*433d6423SLionel Sambuc 	exit(0);
42*433d6423SLionel Sambuc 
43*433d6423SLionel Sambuc       case -1:
44*433d6423SLionel Sambuc 	perror("fork broke");
45*433d6423SLionel Sambuc 	exit(1);
46*433d6423SLionel Sambuc 
47*433d6423SLionel Sambuc       default:
48*433d6423SLionel Sambuc 	/* Parent code */
49*433d6423SLionel Sambuc 	for (i = 0; i < NUM_BLOCKS; i++) write(pipefd[1], buffer, BLOCK_SIZE);
50*433d6423SLionel Sambuc 	wait(&stat_loc);
51*433d6423SLionel Sambuc 	break;
52*433d6423SLionel Sambuc   }
53*433d6423SLionel Sambuc   quit();
54*433d6423SLionel Sambuc   return(-1);			/* impossible */
55*433d6423SLionel Sambuc }
56*433d6423SLionel Sambuc 
57