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

#include 
#include 
#include 

//创建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)