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. |
|
 |
11-18-2008, 10:48 AM
|
#1
|
|
Member
Registered: Jul 2008
Posts: 33
Rep:
|
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.
|
|
|
|
11-18-2008, 12:23 PM
|
#2
|
|
Member
Registered: Aug 2003
Distribution: Slackware 12.1, Slackware Current, Ubuntu Hardy Heron 8.04
Posts: 110
Rep:
|
Quote:
Originally Posted by john.daker
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!
|
|
|
|
11-18-2008, 10:14 PM
|
#3
|
|
Member
Registered: Jul 2008
Posts: 33
Original Poster
Rep:
|
It's C.
Maybe I didnt use the right keyword, cannot found anything valuable.
|
|
|
|
11-19-2008, 12:24 AM
|
#4
|
|
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 2,967
Rep: 
|
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.
|
|
|
|
11-19-2008, 01:53 AM
|
#5
|
|
Member
Registered: Jul 2008
Posts: 33
Original Poster
Rep:
|
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
|
|
|
|
11-19-2008, 04:40 PM
|
#6
|
|
Senior Member
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783
Rep:
|
I can't find a reason why to use processes (fork()) and not pthreads when you want to have shared memory....
|
|
|
|
11-19-2008, 09:47 PM
|
#7
|
|
Senior Member
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 2,967
Rep: 
|
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
|
|
|
|
| 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 01:01 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
|
|