1 Star 0 Fork 0

chyyuu/os-usrapp-lab

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ex1.c 688 Bytes
一键复制 编辑 原始数据 按行查看 历史
Yu Chen 提交于 2022-05-05 12:21 +08:00 . add comments in ipc/pipe/ex1.c
//https://zhuanlan.zhihu.com/p/402341124
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
int main()
{
__pid_t pid;
int fd[2];
char str[20];
pipe(fd);
if ((pid = fork() == 0))
{
printf("children\n");
close(fd[1]);
int num;
while ((num = read(fd[0], str, sizeof(str)) != 0))
{
printf("read: %s", str);
}
}
else
{
printf("parent\n");
close(fd[0]);
for (int i = 0; i < 10; i++)
{
sprintf(str, "the %d message. \n", i);
printf("write: %s", str);
write(fd[1], str, sizeof(str));
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chyyuu/os-usrapp-lab.git
git@gitee.com:chyyuu/os-usrapp-lab.git
chyyuu
os-usrapp-lab
os-usrapp-lab
main

搜索帮助