Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uupsi!kepler1!jwu From: jwu@kepler.com (Jasper Wu) Newsgroups: comp.unix.programmer Subject: problems with shmdt/shmat on SuSunOs 4.1.1 Message-ID: <593@kepler1.kepler.com> Date: 7 Jun 91 17:43:47 GMT Reply-To: jwu@kepler.com (Jasper Wu) Organization: Kepler Financial Management, Ltd., Setauket, NY. Lines: 47 I have a problem in using shmat/shmdt on Sun IPC runing SunOS 4.1.1. When i tried to access a shared memory region created by another process, i got different behaviors on shmdt, depending on whether i set SHM_RDONLY flag or not when i did shmat. Consider the following simlified codes: (error checking omitted for simplicity.) (shmem created by another process with shmget(key,shmsize,IPC_CREATE|0666).) id = shmget(key, shmsize, perm); (perm could be 0777, 0666, 0444, 0, 0644,.. no differences on the results.) addr = shmat(id, 0, 0); shmdt(addr); "shmdt" succeeded as expected. But if changed "shmat" line to: addr = shmat(id, 0, SHM_RDONLY); then "shmdt" failed with EINVAL (Invalid argument). Both shmat returned the same addr.(0xf7700000 when i tested it) Manpage said: shmdt() will fail and not unmap the shared memory segment if: EINVAL shmaddr is not the data segment start address of a shared memory segment. Doesn't sound like the reason to me since i used addr returned by shmat and both shmat returned the same addr. So, what's special about the SHM_RDONLY flag? Is this the way it's supposed to work? Or perhaps it's a "feature" on SunOS 4.1.1 :-). Any ideas would be appreciated. -jasper =========================== jasper wu jwu@kepler.com