无名管道

无名管道源码

#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;  
}  
posted @ 2021-11-05 14:11  roverqqq  阅读(69)  评论(0)    收藏  举报