#include#include #include int value = 5; int count = 0; int main() { pid_t pid; pid = fork(); if (pid == 0) { count ++; printf("count_pid0 = %dn",count); printf("child onen"); printf("child twon"); value = value + 15; printf("333n"); count++; printf("count_pid0_second = %dn",count); return 0; } else if (pid > 0) { count ++; printf("count_pid1 = %dn",count); printf("father onen"); printf("father twon"); wait(NULL); printf("value = %dn", value); return 0; } }
总结:pid>0 为父进程,=0 为子进程;同时运行;先运行父进程,再运行子进程,如果父进程中用wait 则等待子进程运行完再运行父进程的后半部分。



