[comp.sys.sun] Problem with shared memory on SunOS 4.1

klemets@sics.se (Anders Klemets) (12/01/90)

I have a client/server application that uses shared memory. The shared
memory segment must be mapped onto the same address by all participating
processes. A client attaches the shared memory segment with

	id = shmget(key, 0, 0);
	addr = shmat(id, 0, 0);

This will make the kernel choose on which address to put the shared memory
segment. This usually turns out to be the "right" address. But if not, I
detach the segment and attach it at the right address with

	shmdt(addr);
	addr = shmat(id, rightaddr, 0);

At this point the call to shmat() always fails on a Sun-4 with SunOS 4.1
It returns with errno: "invalid argument." I have never experienced that
this code would fail on SunOS 4.0.3 or on System V release 3.2. 

What could be wrong? It seems unlikely that the memory pointed at by
"rightaddr" would be in use by some other part of the process.

Anders Klemets			klemets@sics.se