#include<unistd.h>
#include<sys/types.h>
#include<errno.h>
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<string.h>
#define INPUT 0
#define OUTPUT 1
#define MAX_DATA_LEN 256
int main()
{
int fd[2];
pid_t pid;
const char sendbuf[]="QST test data!";
char rebuf[MAX_DATA_LEN];
int count;
if (pipe(fd)<0)
{
printf("pipe create error\n");
exit(1);
}
if ((pid=fork())==-1)
{
printf("fork create error\n");
}
if(pid==0)
{
printf("in the child process...\n");
close(fd[INPUT]);
write(fd[OUTPUT],sendbuf,strlen(sendbuf));
printf("child pross write: & s\n",sendbuf);
exit(0);
}
else
{
printf("in the parent process...\n");
close(fd[OUTPUT]);
count=read(fd[INPUT],rebuf,MAX_DATA_LEN);
printf("Received from child pross % d bytes:% s\n",count,rebuf);
exit(0);
}
}
