打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Pipe
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#define BUFF_SIZE 20

int main(int argc, char **argv)
{
    int fd[2];
    int pid;
    int pip_id;
    char buff[BUFF_SIZE];
    char buff_size[BUFF_SIZE] = "hello!\n";

    pip_id = pipe(fd);                                                        //Create Pipe
    if (pip_id < 0)
        return -1;

    if ((pid = fork()) < 0) {                                              // Create process
        perror("Create pid failed");
        return -1;
    }

    if (pid == 0) {                                                      // Child process

        while (1) {
            write(fd[1], buff_size, sizeof(buff_size));

            sleep(1);
        }

    } else {
        while (1) {
            read(fd[0], &buff, sizeof(buff));                   // Father process
            sleep(1);
            printf("buff = %s\n", buff);


        }
    }

    return 0;
}
 
                                            _________________
   read(fd[0])  <------------   |________pipe______| <------------- write(fd[1])
                                         
                                 
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
linux进程间通信方式之匿名管道
Linux进程间通信
Linux系统管道和有名管道的通信机制
MPlayer从模式说明
C语言进程间通信(一)
linux程序设计
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服