日期:2014-05-16  浏览次数:20757 次

依然写时复制的疑惑
昨天发帖问的关于写时复制的问题,大体上有了一定了解。但是我做了实验,发现不对啊:在子进程里面写变量之后查看变量地址,发现地址还是跟父进程一样。
结果:
sqNum1[g]  in child  is 161970448
sqNum1[g]  in parent is 161970448

代码:
if((ntid[g]=fork())<0)
                      {  
                         printf("can't creat new process\n");
                         exit(1);  
                      }                   

                     else 
                      {
                        signal(SIGCHLD,SIG_IGN);
                        if(ntid[g]==0)
                         {           
                              //sqNum1[g]++;//操作数据或者不操作
                              sqCHLD=sqNum1[g]; //读
                            if(signal(SIGUSR1,sig_usr_sq)==SIG_ERR)
                              printf("can't catch SIGUSR1\n");                                                                        
                              sqCHLD_pro=sqCHLD; 
                           while(1)
                              {                     
           &