#include<unistd.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sys/types.h>
int main(void)
{
//define some var
pid_t pc;
int pp;
int mfd[2];
char parray[10];
char carray[10];
//create a pipe
pp=pipe(mfd);
//judge if wrong
if(pp<0)
{
printf("pipe error\n");
}
pc=fork();
//parent process
if(pc<0)
{
printf("create process error\n");
}
else
if(pc>0)
{
parray="helloworld";
int a=write(mfd[1],parray,10);
if(a<0)
printf("write error");
}
//child process
if(pc==0)
{
int b=read(mfd[0], carray,10);
if(b>0)
prntf("read ok");
printf("child read is: %s\n",carray);
}
return 0;
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sys/types.h>
int main(void)
{
//define some var
pid_t pc;
int pp;
int mfd[2];
char parray[10];
char carray[10];
//create a pipe
pp=pipe(mfd);
//judge if wrong
if(pp<0)
{
printf("pipe error\n");
}
pc=fork();
//parent process
if(pc<0)
{
printf("create process error\n");
}
else
if(pc>0)
{
parray="helloworld";
int a=write(mfd[1],parray,10);
if(a<0)
printf("write error");
}
//child process
if(pc==0)
{
int b=read(mfd[0], carray,10);
if(b>0)
prntf("read ok");
printf("child read is: %s\n",carray);
}
return 0;
}