LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 12-04-2008, 11:50 PM   #1
rajkiran.ravi
LQ Newbie
 
Registered: Dec 2008
Posts: 2

Rep: Reputation: 0
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
 
Old 12-06-2008, 03:59 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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.
 
Old 12-08-2008, 01:04 AM   #3
rajkiran.ravi
LQ Newbie
 
Registered: Dec 2008
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
Old 12-08-2008, 02:50 AM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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
 
Old 12-08-2008, 08:59 AM   #5
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,377

Rep: Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108Reputation: 1108
I'm not aware of any situation where a lock held by a process won't get cleaned-up when it dies...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to identify a zombie process and control it after parent dies vijaya_svk Programming 1 01-21-2008 04:44 AM
Bash child process in foreground while parent dies kborgnis Programming 3 11-09-2007 06:50 AM
Red Hat AS 4, Nic dies during boot process zmag2linux Red Hat 1 04-20-2007 04:56 PM
Process dies, when transfering files greater than 4 gig Whiskers Linux - General 2 05-14-2005 07:17 PM
Process dies when i try to browse mounted SAMBA windows share poko Linux - Software 1 08-12-2004 11:40 PM


All times are GMT -5. The time now is 12:00 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration