#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// 创建procnum个子进程,每个进程循环loopnum次
int main(void)
{
int procnum = 0, loopnum = 0;
int i = 0, j = 0;
pid_t fpid;
printf("procnum: ");
scanf("%d", &procnum);
printf("loopnum: ");
scanf("%d", &loopnum);
for (i = 0; i < procnum; i++) {
fpid = fork();
if (fpid == 0) {
for (j = 0; j < loopnum; j++){
printf("loopnum: %d\n", j);
}
exit(0);
}
}
return 0;
}
fork函数02
最新推荐文章于 2024-04-28 15:22:09 发布