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