首页 > 其他 > 详细

C waitpid

时间:2015-05-08 14:47:23      阅读:148      评论:0      收藏:0      [点我收藏+]

 

//main.c
#include<stdio.h>
#include<pthread.h>
int main(int argc, char *argv[]) { pid_t pid = fork(); int status; if (pid == 0) { printf("pid == 0 execvp\n"); execvp ("/home/daichenghui/c/os/child_process.o", NULL); //printf("pid == 0\n"); //这一句不会被执行 } else if (pid > 0) { printf("parent process begin to wait...\n"); waitpid(pid, &status, 0); printf("parent end\n"); } else { printf("fork error!\n"); } }

 

// child_pocess.c
#include<stdio.h>

int main(int argc, char *argv) {
    int time = 10;
    while (time--) {
        printf("child process i:%d\n", time);
        sleep(1);
    }

    printf("child process exit\n");
}

 

parent process begin to wait...
pid == 0 execvp
child process i:9
child process i:8
child process i:7
child process i:6
child process i:5
child process i:4
child process i:3
child process i:2
child process i:1
child process i:0
child process exit
parent end

 



C waitpid

原文:http://www.cnblogs.com/muhe221/p/4487576.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!