/****fork_test.c *****/#include#include#includemain(){ pid_t pid; /*此时仅有一个进程*/ int n=4; pid=fork(); /*此时已经有两个进程在同时运行*/ if(pid<0) PRintf("error in fork!/n");else if(pid==0) /*返回0表示子进程*/ { n++; printf("I am the child process, my process ID is %d,n=%d/n",getpid(),n); } else /*返回大于0表示父进程*/ { n--; printf("I am the parent process, my process ID is %d,n=%d/n",getpid(),n); }}