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.
I am trying to create a program that access a shared memory area but doesnt know its size. At the beginning of the area, there is a variable(int) that contains the full area size. So I am trying to map enough space to read the total size, and remap the whole area. I am using POSIX (realtime) shared memort functions: shm_open(), ftruncate(), mmap(), munmap(), shm_unlink().
The problem is that if I truncate a small area (enough to read the full size), and than truncate the file descriptor again with its new size, the previous content of the shared memory area gets overwritten with 0.
I could truncate a bigger area than the shared memory possibly could be (limiting the maximum size of it), read the size, and than truncate (with a smaller size this time). It works, but I dont think this is an elegant solution since I am maping a big memmory area, just to read few bytes and than unmaped it.
Follow a simplified version of the code to express what I intent to do. I am using the solution I mentioned above (using a bigger area):
Has anyone tried to do something similar? Any suggestions? I also tried closing the shared memory descriptor and opening again. But also didnt work. I am running under OpenSuse 13.2.
Thank you guys,
Dante
(1) Attempt to open the shared-memory segment by name.
(2) If (RC == -1) the segment does not exist, then you are the first: create it, then "ftruncate()" it to its maximum size.
(3) In any case, map the memory, or some appropriately-sized "window" thereunto, into each process.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.