2005-04-21 16:53:53 +02:00
|
|
|
/* test 13 */
|
|
|
|
|
|
|
|
/* File: pipes.c - created by Marty Leisner */
|
|
|
|
/* Leisner.Henr 1-Dec-87 8:55:04 */
|
|
|
|
|
|
|
|
/* Copyright (C) 1987 by Martin Leisner. All rights reserved. */
|
|
|
|
/* Used by permission. */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define BLOCK_SIZE 1000
|
|
|
|
#define NUM_BLOCKS 1000
|
|
|
|
|
|
|
|
char buffer[BLOCK_SIZE];
|
|
|
|
|
2013-04-16 18:04:46 +02:00
|
|
|
int max_error = 2;
|
|
|
|
#include "common.h"
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
|
2012-03-24 16:16:34 +01:00
|
|
|
int main(void);
|
|
|
|
void quit(void);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int stat_loc, pipefd[2];
|
|
|
|
register int i;
|
|
|
|
|
2011-12-16 15:45:53 +01:00
|
|
|
start(13);
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
pipe(pipefd);
|
|
|
|
|
|
|
|
switch (fork()) {
|
|
|
|
case 0:
|
|
|
|
/* Child code */
|
|
|
|
for (i = 0; i < NUM_BLOCKS; i++)
|
|
|
|
if (read(pipefd[0], buffer, BLOCK_SIZE) != BLOCK_SIZE) break;
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
perror("fork broke");
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* Parent code */
|
|
|
|
for (i = 0; i < NUM_BLOCKS; i++) write(pipefd[1], buffer, BLOCK_SIZE);
|
|
|
|
wait(&stat_loc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
quit();
|
|
|
|
return(-1); /* impossible */
|
|
|
|
}
|
|
|
|
|