您的位置:首页 > 运维架构 > Linux

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);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: