管道简单使用模板

#include <unistd.h>
#include <stdio.h>

int main()

{
        int fd[2];
        int ret = pipe(fd);
        char readBuf[15];
        if(ret < 0) perror("pipe(fd)");
        pid_t pid  = fork();
        if(pid ==0)
        {
                close(fd[0]);
                write(fd[1],"hello 360\n",10);

        }
        else
        {
                close(fd[1]);
                read(fd[0],readBuf,10);
                printf("%s\n",readBuf);
                //sleep(1);
        }
        return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37967635/article/details/83504703