| Rev | Line | |
|---|
| [9] | 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 | int errct = 0;
|
|---|
| 19 | char buffer[BLOCK_SIZE];
|
|---|
| 20 |
|
|---|
| 21 | _PROTOTYPE(int main, (void));
|
|---|
| 22 | _PROTOTYPE(void quit, (void));
|
|---|
| 23 |
|
|---|
| 24 | int main()
|
|---|
| 25 | {
|
|---|
| 26 | int stat_loc, pipefd[2];
|
|---|
| 27 | register int i;
|
|---|
| 28 | pipe(pipefd);
|
|---|
| 29 |
|
|---|
| 30 | printf("Test 13 ");
|
|---|
| 31 | fflush(stdout); /* have to flush for child's benefit */
|
|---|
| 32 |
|
|---|
| 33 | system("rm -rf DIR_13; mkdir DIR_13");
|
|---|
| 34 | chdir("DIR_13");
|
|---|
| 35 |
|
|---|
| 36 | pipe(pipefd);
|
|---|
| 37 |
|
|---|
| 38 | switch (fork()) {
|
|---|
| 39 | case 0:
|
|---|
| 40 | /* Child code */
|
|---|
| 41 | for (i = 0; i < NUM_BLOCKS; i++)
|
|---|
| 42 | if (read(pipefd[0], buffer, BLOCK_SIZE) != BLOCK_SIZE) break;
|
|---|
| 43 | exit(0);
|
|---|
| 44 |
|
|---|
| 45 | case -1:
|
|---|
| 46 | perror("fork broke");
|
|---|
| 47 | exit(1);
|
|---|
| 48 |
|
|---|
| 49 | default:
|
|---|
| 50 | /* Parent code */
|
|---|
| 51 | for (i = 0; i < NUM_BLOCKS; i++) write(pipefd[1], buffer, BLOCK_SIZE);
|
|---|
| 52 | wait(&stat_loc);
|
|---|
| 53 | break;
|
|---|
| 54 | }
|
|---|
| 55 | quit();
|
|---|
| 56 | return(-1); /* impossible */
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | void quit()
|
|---|
| 60 | {
|
|---|
| 61 |
|
|---|
| 62 | chdir("..");
|
|---|
| 63 | system("rm -rf DIR*");
|
|---|
| 64 |
|
|---|
| 65 | if (errct == 0) {
|
|---|
| 66 | printf("ok\n");
|
|---|
| 67 | exit(0);
|
|---|
| 68 | } else {
|
|---|
| 69 | printf("%d errors\n", errct);
|
|---|
| 70 | exit(1);
|
|---|
| 71 | }
|
|---|
| 72 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.