#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
int main() {
int n;
scanf("%d", &n);
// 循环创建 n 个进程
int i;
for (i = 0; i < n; i++) {
if (fork() == 0) {
break;
}
}
if (i == n) {
sleep(n);
printf("father\n");
} else {
sleep(i);
printf("第 %d 个子进程\n", i);
}
return 0;
}
标签:int,循环,sleep,printf,进程,include,若干个
From: https://www.cnblogs.com/hacker-dvd/p/17533506.html