Linux练习(wait父进程等待子进程)
2012-09-28 16:23
106 查看
#include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <stdio.h> int main() { pid_t pid; char *m; int n; pid=fork(); if(pid==0) { m="this is child"; n=5; } else { m="this is father"; n=3; } for(;n>0;n--) { puts(m); sleep(1); } if(pid!=0) { pid_t child_pid; child_pid=wait(NULL); printf("child has finished: %d\n",child_pid); } exit(0); }
相关文章推荐
- 父进程 等待子进程初始化后才使用子进程_waitforinputidle
- linux下的wait()实现等待一个子进程和所有子进程退出
- linux中fork函数及子进程父进程的关系 (总结的很好)
- 如何测试Linux 中的wait函数能不能等待子进程的子进程?
- Linux下父进程异步等待子进程
- linux内核中等待队列(wait_event,wake_up...)
- linux内核的等待队列使用方法,wait_queue_head_t,进程休眠
- Linux--等待进程结束wait()和waitpid()
- Linux下利用fork()创建子进程并使父进程等待子进程结束
- 父进程等待子进程终止 wait, WIFEXITED, WEXITSTATUS
- 发现并解决linux高I/O Wait问题 – 如何发现linux中引起高io等待的进程
- 父进程 等待子进程初始化后才使用子进程_waitforinputidle
- 带超时的等待子进程,timed_wait
- Linux下父进程通过管道发送文件名给子进程,子进程获取文件名后首先判断文件是否存在,不存在,通过管道返回错误信息,存在,将文件内容返回给父进程
- 父进程等待子进程终止 wait, WIFEXITED, WEXITSTATUS
- linux下的进程等待(wait和waitpid)
- linux等待队列wait_queue_head_t和wait_queue_t
- linux等待队列wait_queue_head_t和wait_queue_t
- Windows和Linux上分别怎样实现等待某个线程结束?---用WaitForSingleObject和pthread_join
- linux内核中等待队列 (函数wait_event与wake_up)