#include<stdio.h>#include<sys/types.h>#include<unistd.h>#include<sys/wait.h>int a=100;intmain(){pid_t a;
a=fork();if(a>0){printf("!!!!!!A=%d\n",a);printf("father pid is %d\n",getpid());}elseif(a==0){
a-=50;printf("*****a=%d\n",a);printf("child pid is %d ppid is %d \n",getpid(),getppid());}return0;}
并没有相同 父进程直接打印初始化值了
1 如果是 父进程 -- 子进程 ++ 呢
会不会影响
#include<stdio.h>#include<sys/types.h>#include<unistd.h>#include<sys/wait.h>int a=100;intmain(){pid_t a;
a=fork();if(a>0){
a-=50;printf("!!!A=%d\n",a);printf("father pid is %d\n",getpid());}elseif(a==0){
a+=50;printf("*****a=%d\n",a);printf("child pid is %d ppid is %d \n",getpid(),getppid());}return0;}