shared memory not same address

hi,

I want a server process to create a segment of shared memory and a client process to be able to access it. I am using the following code.
Server:
void *shared_memory=(void *)0;
shmid=shmget((key_t)998,1024,0666 | IPC_CREAT);
shared_memory=shmat(shmid,(void *)0,0);

Client
shmid=shmget((key_t)998,1024,0666);
shared_memory=shmat(shmid,(void *)0,0);

when in each process I display the address of memory to which shmat is attaching each process, the values are different,

what am I doing wrong? I would think that the addresses returned by shmat are the same for both the client and server processes, thanks
closed account (S6k9GNh0)
Weren't sockets made for this very purpose? To transmit data between processes?
man shmat

Weren't sockets made for this very purpose? To transmit data between processes?


Yes, between processes on different machines. However, there's no need to pay serialization costs if all processes are on the same machine. In some applications this matters.

all processes are on the same machine


oth, why not just use threads here?
Topic archived. No new replies allowed.