LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shmat() with fixed address (https://www.linuxquestions.org/questions/linux-newbie-8/shmat-with-fixed-address-848401/)

poojithas 12-04-2010 07:59 PM

shmat() with fixed address
 
Hi,

I'm using Ubuntu 10.04 on a 64bit machine.

In my shmat() call, I want to assign fixed memory address to shmaddr variable. I have no idea which address value to give. Some where in the net I read we can make use of sysproc info to know the user space addresses, but could not figure out how to get that, please help on this.

void *shmat(int shmid, const void *shmaddr, int shmflg);

Note:
-----
the reason I want to use fixed address is to build linked list on the shmget() returned memory and my other process will map into fixed address and access the linked list.

stevexyz 12-15-2010 07:02 PM

Hi there,

You likely do not need to know where the memory is going to be mapped:

1. Use ftok() to construct a key for the shared memory .
2a. In one process use shmget() with IPC_CREATE to create a sufficiently large shared memory segment.
2b. In your other processes use shmget() without IPC_CREATE.
3. In all the processes you then call shmat() with the id from shmget() and a NULL shmaddr. In each process shmat() returns where the memory has been mapped, that's the start of the shared segment.

Cheers, Steve


All times are GMT -5. The time now is 11:36 AM.