Pipeline Communications
2016-08-23
0 0 0
no vote
Other
Earn points
int main(int argc, char **argv)
{
int pipefds[2],pipefds2[2];
pid_t pid;
int i,j;
char buffer[255];
If (pipe (pipefds) < 0)//first pipeline
{
printf("errorn");
}
pid=fork();
if(pid<0)
exit(1);
if (pid==0)
{
close(pipefds[1]);
memset(buffer,0,sizeof(buffer));
while(1)
{
I=read (pipefds[0],buffer,sizeof (buffer));//if it is empty (preceded by a child process after the fork), then block does not move
if(0==i)
break;
printf("%sn",buffer);
}
close(pipefds[0]);
exit(0);
}
else
{
close(pipefds[0]);
scanf("%s",buffer);
write(pipefds[1],buffer,strlen(buffer));
close(pipefds[1]);
wait(NULL);
exit(0);
}
}
c
通信
管道
Related Source Codes
PClite
0
0
no vote
generic embeded FTP Client
0
0
no vote
UDP Test Demo
0
0
no vote
TMS320F28335 DSP transmits data to EEPROM through
0
0
no vote
TMS320F28335 CAN communication source code
0
0
no vote
No comment