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.
This is my first time on the forum. Need help with POSIX RWLocks in Shared Memory.
I have the following scenario:
A process creates an SHM area and initializes an RWLock in the SHM area. If it takes the lock and gets killed, is there any way to release this lock?
I would look at mmap as a replacement for shm; shm causes quite a few problems related to what you're saying, namely that the segment won't be freed unless one process flags it, even if no existing process holds reference to it. You really shouldn't have to ask that question; it should happen automatically. If it doesn't then that sounds like a majorly-flawed system to me.
ta0kira
PS As with anything that has external cleanup, though, you should have a signal handler for every possible signal that can cause termination that will unlock the memory. The exception is SIGKILL, but there's nothing you can do about that. That's why SIGKILL is highly discouraged.
So you're saying that the locks with shm only (i.e. not mmap) are persistent? That sounds accurate. If that's actually the case then that is the reason I recommend mmap because it should take care of all of that; locks should be associated with the file, and file locks should dissolve when the process exits. With shm, though, you don't have anything underlying except for actual memory.
ta0kira
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.