On Wed, 13 Mar 2002, David T. Lewis wrote:
On Wed, Mar 13, 2002 at 02:48:26PM +0100, Bert Freudenberg wrote:
It is just not a good idea to call shmExit() in the child.
Also, you should be using _exit() instead of exit() when exec() failed, because the latter calls the atexit functions which harm the running image.
Great, thank you! Help me understand, though: Was the call to shmExit() destroying the shared memory segment when running with -xshm?
Yes, because stFree(), called by shmExit(), calls shmctl(IPC_RMID) which destroys the segment. Which might have been okay if shmExit() had reset stDisplayBitmap to 0 so the segment gets recreated on the next ioShowDisplay().
Thinking about this, shmExit() probably even got called twice: once from your call, once via AT_EXIT by exec(). So to prevent future errors in here, shmExit() really should reset stDisplayBitmap.
I would have thought that the shared memory segment would stay in place until the last reference to it went away (in the parent). My intention was to make sure the child processes disconnected themselves from the shared memory before the exec()
After both, exec() and exit(), all attached shared memory segments are detached automatically. So it's at least superfluous to do this.
Although we'll have to think again if using _exit() per my suggestion doesn't circumvent this automatism - there might be a dangling segment now. I cannot recall the tool name that lists shared segments ... anyone?
-- Bert