📄 pipe.c
字号:
#include <unistd.h>
#include <stdio.h>
char *id = "pipe.c is a test unnamed_pipe example\n";
void main(){
int fd[2];
char buf[256]="Hello,everybody:do you understand";
int n, count = 0;
write(2,id,strlen(id));
if(pipe(fd)==-1){
perror("pipe");
exit(1);
}
switch(fork()){
case 0: /* child process */
close(fd[0]);
while((count<4096)&&((n = write(fd[1],buf,strlen(buf)))>0))
count +=n;
exit(0);
case -1:
perror("fork");
exit(1);
default: /* parent process */
close(fd[1]);
while((count<4096)&&((n = read(fd[0],buf,strlen(buf)))>0))
count +=n;
printf("%d bytes of data received from child process:%s\n",count,buf);
exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -