通道实现进程间通信

来源:互联网 发布:三菱编程手册da 编辑:程序博客网 时间:2024/06/06 13:22

fork创建子进程,pipe及read、write实现进程间通信

#include <stdio.h>#include <unistd.h>main(){        int i;        int ppid[2];        pipe(ppid);        int pid = fork();        if (0 == pid)        {                write(ppid[1],"test",sizeof("test"));        }        else        {                char buf[128] = {0};                read(ppid[0],buf,128);                printf("buf is %s\n",buf);        }}


原创粉丝点击