Are pointers in a shared memory segment valid for a different process?

Conor P. Cahill cpcahil at virtech.uucp
Fri Aug 24 21:50:09 AEST 1990


In article <838 at qusunc.queensu.CA> kelley at qucis.queensu.CA (Todd Kelley) writes:
>
>	[Question of using pointers to shared memory segments between two
>	 processes deleted]
>

The easiest way to do this is to ensure that both processes attach the
segment at the same address.  In that case, any pointers within the segment
will be the same for both processes.

The following algorithm could be used:

	creat a new segment
	attach at default address
	calculate extra space needed and re-attach the segment far enough
		away from your data segment so that you wont run out of malloc
		space
	save the address that it was attached at in the first portion of the
		shared memory segment.

For other processes:
	get segment id
	attach segment at default address
	get correct attachment address (from the shared memory segment itself)
	detach & re-attach at the correct address.

The only thing you need to ensure is that when you are leaving enough room 
between the shared memory segment and your program's standard data segment
you must ensure that the resultant address is far enough down for any programs
that are going to use this shared memory segment.

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 



More information about the Comp.unix.wizards mailing list