How can I use shared memory for Inter Process Communication?

Todd Kelley kelley at qucis.queensu.CA
Sun Aug 19 05:29:50 AEST 1990


Hello unix experts,

My question concerns IPC using sockets and shared memory on a Sun4
running SunOS 4.01.

I am working on a program consisting of several processes (all with
a common ancestor) which pass arrays of data to each other through
sockets.  One process accepts queries from the other processes, gets
data out of a database and puts it into memory obtained from malloc(),
then copies it into a socket to the inquiring process.  Once the data
is sent over the socket, the memory can be freed.

Since all the processes are on the same machine, I would like to pass
just a pointer to the data through the socket.  I've assumed that such
a pointer would be required to point into a shared memory segment
that the receiving process can attach and access.

I would like to use shmget(2) the same way I use malloc(), but from
RingTFM I get the impression that shared memory is not designed to
be used this way.  I performed an experiment, and discovered that a
single process cannot create more than 100 shm segments, implying
that the system wide limit on shm segments is about 100.  I can't
guarantee that there will always be less than 100 pending messages.

How is shared memory normally used for IPC of this nature?

Please respond by email, and if I get at least one response, I'll
post a summary.



More information about the Comp.unix.questions mailing list