Linux进程/线程协作 之 创建指定数量的进程

来源:互联网 发布:淘宝会员名一般叫什么 编辑:程序博客网 时间:2024/05/19 10:54
#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;}
0 0