我对这个小程序有疑问:
int main() {
pid_t process;
int count= 0;
switch(process= fork()) {
case -1:
printf("Fork error!\n\n");
exit(1);
break;
case 0: //child
printf("Process CHILD: PID= %d, Value= %d \n", getpid(), process);
printf("Coounter NOT increased: %d\n", count);
printf("Increase counter...\n");
sleep(2);
count= count + 2;
printf("Counter increased: %d\n\n", count);
exit(0);
break;
default: //parent
wait(0);
printf("Process PARENT: PID= %d, Value= %d\n", getpid(), process);
printf("Counter value: %d\n\n", count);
break;
}
return 0;
}
我增加了孩子的计数器,但在父母的计数器没有增加......为什么?
谢谢大家