1 Star 0 Fork 0

吴泳淋/信息安全系统设计与实现

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
C3.7.c 829 Bytes
一键复制 编辑 原始数据 按行查看 历史
吴泳淋 提交于 2021-10-25 16:54 +08:00 . add C3.7.c.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int pd[2], n, i;
char line[256];
int main()
{
pipe(pd);
printf("pd=[%d,%d]\n", pd[0], pd[1]);
if (fork())
{
printf("parent %d close pd[0]\n", getpid());
close(pd[0]);
while (i++ < 10)
{
printf("parent %d writing to pipe\n", getpid());
n = write(pd[1], "Hello, I'm 20191218tqh!", 32);
printf("parent %d worte %d bytes to pipe\n", getpid(), n);
}
printf("parent %d exit\n", getpid());
}
else
{
printf("child %d close p[1]\n", getpid());
close(pd[1]);
while (1)
{
printf("child %d reading from pipe\n", getpid());
if ((n = read(pd[0], line, 128)))
{
line[n] = 0;
printf("child read %d bytes fron pipe: %s\n", n, line);
}
else
exit(0);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wu_yong_lin/XinXiAnQuan.git
git@gitee.com:wu_yong_lin/XinXiAnQuan.git
wu_yong_lin
XinXiAnQuan
信息安全系统设计与实现
master

搜索帮助