want to get 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 ?
|