Linux下父子进程匿名管道通信

来源:互联网 发布:手机淘宝网试衣间在哪 编辑:程序博客网 时间:2024/05/17 13:12
#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<string.h>int main(){int fd[2];char buf[30],str[30];pipe(fd);pid_t pid1=fork();if(pid1==0){sprintf(buf,"this an example\n");printf("child is running,please input words!\n");write(fd[1],buf,30);sleep(3);}else{wait(5);read(fd[0],str,30);printf("%s\n",str);}return 0;}

0 0
原创粉丝点击