Programming This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
12-04-2008, 11:50 PM
|
#1
|
|
LQ Newbie
Registered: Dec 2008
Posts: 2
Rep:
|
Releasing RWLocks from SHM when process dies
Hi
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?
Raj
|
|
|
|
12-06-2008, 03:59 PM
|
#2
|
|
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 2,962
Rep: 
|
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.
Last edited by ta0kira; 12-06-2008 at 04:08 PM.
|
|
|
|
12-08-2008, 01:04 AM
|
#3
|
|
LQ Newbie
Registered: Dec 2008
Posts: 2
Original Poster
Rep:
|
Thanks for the reply.
Infact I am using Posix based shared memory also... for which I did an shm_open, ftruncate and mmap()
However, for some reason the locks in SHM are not released. Shouldnt this be the responsibility of the kernel to clean up the lock?
Thanks
|
|
|
|
12-08-2008, 02:50 AM
|
#4
|
|
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 2,962
Rep: 
|
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
|
|
|
|
12-08-2008, 08:59 AM
|
#5
|
|
Senior Member
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 4,554
|
 I'm not aware of any situation where a lock held by a process won't get cleaned-up when it dies...
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:30 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|