程序的流程图,清楚地显示了从创建到终止的父子流程执行

pid_t pid;
printf("Begin");
if (fork() == 0) {
    printf("First if fork==0");
    if (fork() != 0) 
        printf("First if fork!=0");
}

if (fork() != 0) {   
    printf("second if fork!=0");
    if (fork() == 0) 
        printf("second if fork==0");
}

printf("End if\n");

I try to understand how fork works. Can you draw a process graph to be understandable for me and for others?

评论