#include #include #include #include #include #include "log.h" //reporting and logging functions void A(); void B(); /* function main ----------------------------------------- */ void main() { pid_t pid; printf("I am the process before fork(), my pid=%u\n", getpid()); if ((pid = fork()) < 0) sys_exit("fork error"); if (pid == 0) // child process B(); // B does not return, it exits else // parent process A(); // A does not return, it exits }/* end main */ /* function A -------------------------------------------- */ void A() { printf("I am doing A, my pid=%u\n",getpid()); fflush(stdout); exit(0); }/* end A */ /* function B -------------------------------------------- */ void B() { printf("I am doing B, my pid=%u\n",getpid()); fflush(stdout); exit(0); }/* and B */