#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <pthread.h>
#include <sys/time.h>
#include <sys/types.h>
#include <math.h>
int pfds[2];
char buf[100000];
void do_fork(void)
{
int n;
sleep(1);
printf("child reading...\n");
n = read(pfds[0], buf, 64524);
printf("%d bytes read\n", n);
_exit(0);
}
int main()
{
pid_t pid;
int n;
if (pipe(pfds) < 0) {
fprintf(stderr, "Couldn't create pipe\n");
exit(1);
}
pid = fork();
if (! pid) {
do_fork();
}
usleep(1000);
printf("main writing...\n");
n = write(pfds[1], buf, 64524);
printf("parent wrote %d bytes\n", n);
// printf("main writing...\n");
// n = write(pfds[1], buf, 100);
// printf("parent wrote %d bytes\n", n);
n = read(pfds[0], buf, 4);
if (n < 0)
perror("read");
printf("parent: %d bytes read\n", n);
getchar();
}