无名管道
无名管道源码
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
int main()
{
int fd[2];
char buf[1024];
memset(buf,'\0',sizeof(buf));
pipe(fd);
if (fork() == 0)
{
close(fd[1]);
read(fd[0], buf, sizeof(buf));
printf("child recv :%s\n", buf);
_exit(0);
}
close(fd[0]);
strcpy(buf, "i am parent pipe");
write(fd[1], buf, strlen(buf) + 1);
return 0;
}

浙公网安备 33010602011771号