#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); }
Linux练习(wait父进程等待子进程)
最新推荐文章于 2024-04-05 14:06:49 发布