fork补充加强
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
int data = 100;
pid_t pid;
printf("father pid is %d\n",getpid());
pid = fork(); //fork后拷贝代码段,父子进程都会执行后面的代码(看运行结果)
if(pid>0){
printf("this is father pid:%d\n",getpid());
}else if(pid == 0){
printf("this id child pid:%d\n",getpid());
data = data+10;
}
printf("data=%d\n",data);
return 0;
}
运行结果: