pipe.c
来自「1、 了解系统调用pipe()的功能和实际原理 2、 编写一段程序」· C语言 代码 · 共 31 行
C
31 行
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{int fd[2];
pid_t x;
char S[100];
pipe(fd);
x = fork();
if (x == 0)
{ printf("Child Process<%d> Send Hello to Father Process!\n", getpid());
sleep(1);
sprintf(S, "Hello from Child Process!");
close(fd[0]);
write(fd[1], S, 50);
close(fd[1]);
sleep(1);
}
else
{//wait(0);
close(fd[1]);
read(fd[0], S, 50);
close(fd[0]);
printf("Father Process<%d> receive the message : ** %s **\n", getpid(), S);
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?