2024年1月15日发(作者:)
分析fork()实验结果:
printf("shm_segsz=%d bytesn", _segsz); printf("parent pid=%d,shm_cpid=%dn",getpid(),_cpid); printf("chlid pid=%d,shm_lpid=%dn",pid,_lpid); //把共享内存映射到本地 shmaddr = (char *)shmat(shmid, NULL, 0); if( (int)shmaddr == -1 ) { perror("shmat addr error"); return -1; } printf("%s",shmaddr); //断开共享内存连接 shmdt(shmaddr); //删除共享内存 shmctl(shmid,IPC_RMID,NULL); } else { perror("fork error"); shmctl(shmid,IPC_RMID,NULL); } return 0;}


发布评论