#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
//创建5个子进程。
int main(int argc, char ** argv) {
pid_t root_pid;
int i = 0;
root_pid = getpid();
printf("Root pid is %d\n", root_pid);
for(i = 0;i < 5; i++) {
if(root_pid == getpid()) {
fork();
}
}
printf("Pid is %d, ppid is %d\n",getpid(), getppid());
while(1) {
sleep(1);
printf("%d waked up.", getpid());
;
}
return 0;
}
Linux进程/线程协作 之 创建指定数量的进程
最新推荐文章于 2024-11-26 20:46:19 发布
本文介绍了一个简单的C语言程序,该程序通过fork()函数创建了五个子进程,并在每个进程中打印了进程ID和父进程ID。此外,每个子进程都会进入无限循环并每隔一秒输出其进程ID。
938

被折叠的 条评论
为什么被折叠?



