ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If two processes attach to the same shared memory segment, is it possible to make shmat() attach the shared memory segment to the same local space address in both processes? In other words, if shmat(shm_id, 0, flags) returns 0xc04ab000 in proc1, I would like shmat() returns the same address in proc2, which is 0xc04ab000.
I could pass 0xc04ab000 as the second parameter when calling shmat(), but since it's from proc1, I have to get it using some sort of IPC. HP-UX returns the same local space address if processes attach to the same segment. Looks like it's not guaranteed in Linux.
To get the same shared memory between two process ,I
think you have to give the same shmid while calling shmat().
So you don't have to pass the address ,you have to pass
the shmid.
Do the following:
1)process1 gets the shared memory by shmget(),
returning a shmid.
2)process1 attaches to the shared memory by shmat() usingthe shmid returned previously.
3)pass the shmid to process2.
4)process2 attaches to the shared memory using the same shmid.
now you are free to use the shared memory as you wish.
then both process should detach themselves and one should release the shared memory.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.