管道的时间问题
来源:互联网 发布:xp php环境搭建 编辑:程序博客网 时间:2024/05/03 16:01
父子进程的时间是一起的 这个程序的运行 write1成功 2秒 write2成功 2秒后 read from pipe
- #include <unistd.h>
- #include <sys/types.h>
- #include <errno.h>
- #include <stdio.h>
- #include <stdlib.h>
- #define MAXLINE 4096 /* max line length */
- int main(void)
- {
- int n;
- int fd[2];
- pid_t pid;
- char line[MAXLINE];
- if (pipe(fd) < 0)//创建管道
- {
- printf("pipe create error/n");
- return -1;
- }
- pid = fork();//创建进程
- if (pid < 0)
- {
- printf("fork create error/n");
- return -1;
- }
- else if (pid > 0) //父进程
- {
- close(fd[0]);
- if(write(fd[1],"Hello",5)!=-1)
- printf("parent write1 success!/n");
- sleep(2);
- if(write(fd[1]," ipc Pipe",9)!=-1)
- printf("parent write2 success!/n");
- close(fd[1]);
- //sleep(2);
- waitpid(pid,NULL,0);//等待子进程中断或结束
- }
- else /* child */
- {
- close(fd[1]);
- sleep(3);
- close(fd[1]);
- n = read(fd[0], line, MAXLINE);
- if(n > 0)
- {
- printf("%d numbers read from the pipe is: %s/n",n,line);
- }
- close(fd[0]);
- exit(0);
- }
- return 0;
- }
- 管道的时间问题
- pb 的数据管道问题
- 管道堵住问题的定位
- 管道引起的变量赋值问题
- 管道 无法改变变量值 的问题
- 防止读匿名管道的无限阻塞问题的方法
- oracle的时间问题
- 时间控件的问题
- 系统的时间问题
- java时间的问题
- 时间安排的问题
- 关于时间的问题
- 关于时间的问题
- 时间显示的问题
- Ubuntu的时间 问题
- Oracle时间的问题
- MySql的时间问题
- 程序设计的时间问题
- 第一次登陆
- 第一天
- ADO.NET --总结
- ext学习笔记
- 哈哈,终于有自己的邮箱啦
- 管道的时间问题
- 打开控制面板DOS命令和RUNDLL32使用大全
- 计算机达人成长之路目录
- 《新概念51单片机C语言教程-入门、提高、开发、扩展全攻略》杂录3
- 沃尔夫问我去热饭我而去
- 分析函数
- 分析函数
- linux
- 哈哈