c多进程
1. fork创建子进程
2. wait等待子进程结束
#include <stdio.h> #include <unistd.h> #include <sys/wait.h> int main() { int count = 0; int pid = fork(); if (pid == 0) { count++; sleep(5); printf("i am child pid: %d, count:%d\n", getpid(), count); } else { count++; printf("i am parent pid: %d, count:%d\n", getpid(), count); // wait等待子进程结束 int cPid = wait(NULL); printf("wait child pid:%d\n", cPid); } return 0; }
Please call me JiangYouDang!