|
发表于 2002-11-10 21:05:45
|
显示全部楼层
An very simple example about pipeline and communication:
#include <unistd.h>
#include <stdio.h>
void main()
{
int pipeID[2];
int len=14;
char msgToChild[]="hello child!";
char childBUF[18];
pipe(pipeID);
if(fork()==0)
{
while(!read(pipeID[0],childBUF,len))
{
read(pipeID[0],childBUF,len);
}
printf("Hi dad,i have received your message: %s\n ",childBUF);
}
else
{
write(pipeID[1],msgToChild,len);
wait(NULL);
}
exit(0);
}
××××××××××××××××××××××××××××××××××××××××××××××××
运行结果:
Hi dad,i have received your message: hello child! |
|