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;
}
文档来源:51CTO技术博客https://blog.51cto.com/u_2498536/3304101
页:
[1]