LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   i want to obtain two different shared memories (https://www.linuxquestions.org/questions/linux-kernel-70/i-want-to-obtain-two-different-shared-memories-439616/)

ankurcse 04-28-2006 03:02 AM

i want to obtain two different shared memories
 
Hi,
i m giving diiferent key values as the 1st argument in shmget() in two different files like, (key_t)12, (key_t)1234. But shmat() is attaching same memeroy address to different processes. Suppose i want two different shared memories for two different processes, then how it can be done. i have tried several possiblities for 1st argument of shmget(), but on doing shmat() i m getting same memory address.


ex:
first.c

main()
{

int *shm_mem, shmid ;

shmid = shmget((key_t)12, sizeof(int)*10, 0666 | IPC_CREAT) ;

shm_mem = shmat(shmid, (void*)0, 0 );

}

second.c

main()
{

int *shm_mem, shmid ;

shmid = shmget((key_t)"/test/test1.c", sizeof(int)*100, 0666 | IPC_CREAT ) ;

shm_mem = shmat(shmid, (void*)0, 0 ) ;

}


Now the problem is: i m getting same value of shm_mem, inspite i m using different key values in shmget().
How i can obtain two different shared memories ?

sundialsvcs 04-28-2006 09:38 AM

Use a different key.

jtshaw 04-28-2006 01:03 PM

Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php


All times are GMT -5. The time now is 09:21 PM.