LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-18-2008, 10:48 AM   #1
john.daker
Member
 
Registered: Jul 2008
Posts: 33

Rep: Reputation: 15
How to lock/unlock the shared memory created by mmap?


Hi,all
I create a shared memory with mmap, and share the memory within parent and child process, now I want to lock/unlock the shared memory, how to do this?

Thanks.
 
Old 11-18-2008, 12:23 PM   #2
dangerboy
Member
 
Registered: Aug 2003
Distribution: Slackware 12.1, Slackware Current, Ubuntu Hardy Heron 8.04
Posts: 110

Rep: Reputation: 15
Quote:
Originally Posted by john.daker View Post
Hi,all
I create a shared memory with mmap, and share the memory within parent and child process, now I want to lock/unlock the shared memory, how to do this?

Thanks.
You didn't state what langauge... many programming languages have an mmap function. A quick Google brought this up in C++

http://publib.boulder.ibm.com/infoce.../apis/mmap.htm

When in doubt, Google it. I taught myself how to program with Google and looking at other people's source code. Good luck!
 
Old 11-18-2008, 10:14 PM   #3
john.daker
Member
 
Registered: Jul 2008
Posts: 33

Original Poster
Rep: Reputation: 15
It's C.
Maybe I didnt use the right keyword, cannot found anything valuable.
 
Old 11-19-2008, 12:24 AM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
That depends on what you mean by "lock." Do you mean protect/unprotect, or lock/unlock in physical RAM? The first can be done with mprotect (subject to limitations by the underlying file/device) and the second can be done with mlock. I don't think either will propagate between parents and children, however.
ta0kira

PS Or maybe you mean lock for exclusive write access? Look at semget if that's the case.

Last edited by ta0kira; 11-19-2008 at 12:26 AM.
 
Old 11-19-2008, 01:53 AM   #5
john.daker
Member
 
Registered: Jul 2008
Posts: 33

Original Poster
Rep: Reputation: 15
process synchronization.
I googled that thread synchronization can use pthread_mutex_lock/unlock, but how process do the lock/unlock?
I created a shared memory, and want lock something , and child can read/modify the shared memory until get the lock
 
Old 11-19-2008, 04:40 PM   #6
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
I can't find a reason why to use processes (fork()) and not pthreads when you want to have shared memory....
 
Old 11-19-2008, 09:47 PM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
There are quite a few valid reasons to use fork vs. threads (and vice-versa) even with shared memory, but that's an entirely different discussion.
ta0kira
 
  


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
Lock screen (requiring password to unlock) when resuming from suspend theoldman Linux - Laptop and Netbook 2 12-17-2009 09:35 PM
How can I lock/unlock passwd file? scorpionaag Linux - Server 2 01-04-2008 08:15 AM
lock and unlock munna_dude Programming 1 05-18-2007 06:03 AM
i need to lock my keyboard and mouse for a short period of time and also unlock them balajitrz Linux - Hardware 3 02-16-2007 12:46 PM
About Lock And Unlock George2 Programming 8 08-23-2005 11:30 PM


All times are GMT -5. The time now is 03:27 PM.

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