标签:
//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
标签:
原文地址:http://www.cnblogs.com/muhe221/p/4487576.html