码迷,mamicode.com
首页 > 其他好文 > 详细

C waitpid

时间:2015-05-08 14:50:32      阅读:96      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!