473,698 Members | 2,888 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mmap and shared memory

Suppose I've a process P1, which generates itself a lot of data , for
example 2Mb.
Then, I've a process P2 which must access P1 shared memory and,
probably, modify this data.
To accomplish this, I've been digging around python's mmap module, but I
can't figure how to use it without files.

Could anybody explain me how could this be accomplished? An example will
be very appreciated. Thanks a lot for your help.

Feb 11 '08 #1
5 6065
Carl Banks wrote:
In C you can use the mmap call to request a specific physical location
in memory (whence I presume two different processes can mmap anonymous
memory block in the same location)
Um, no, it lets you specify the *virtual* address in the process's
address space at which the object you specify is to be mapped.

As far as I know, the only way two unrelated processes can share
memory via mmap is by mapping a file. An anonymous block is known
only to the process that creates it -- being anonymous, there's
no way for another process to refer to it.

However, if one process is forked from the other, the parent
can mmap an anonymous block and the child will inherit that
mapping.

(I suppose if both processes had sufficient privileges they
could map physical memory out of /dev/mem, but that would be
*really* dangerous!)

--
Greg
Feb 13 '08 #2
greg wrote:
Carl Banks wrote:
>In C you can use the mmap call to request a specific physical location
in memory (whence I presume two different processes can mmap anonymous
memory block in the same location)

Um, no, it lets you specify the *virtual* address in the process's
address space at which the object you specify is to be mapped.

As far as I know, the only way two unrelated processes can share
memory via mmap is by mapping a file. An anonymous block is known
only to the process that creates it -- being anonymous, there's
no way for another process to refer to it.
On POSIX systems, you can create a shared memory object without a file
using shm_open. The function returns a file descriptor.
However, if one process is forked from the other, the parent
can mmap an anonymous block and the child will inherit that
mapping.

(I suppose if both processes had sufficient privileges they
could map physical memory out of /dev/mem, but that would be
*really* dangerous!)

--
Greg
Feb 13 '08 #3
In article <Ko************ *************** ***@comcast.com >,
Jeff Schwab <je**@schwabcen ter.comwrote:
greg wrote:
Carl Banks wrote:
In C you can use the mmap call to request a specific physical location
in memory (whence I presume two different processes can mmap anonymous
memory block in the same location)
Um, no, it lets you specify the *virtual* address in the process's
address space at which the object you specify is to be mapped.

As far as I know, the only way two unrelated processes can share
memory via mmap is by mapping a file. An anonymous block is known
only to the process that creates it -- being anonymous, there's
no way for another process to refer to it.

On POSIX systems, you can create a shared memory object without a file
using shm_open. The function returns a file descriptor.
Sorry I missed the OP, but you might be interested in this shared memory
module for Python:
http://NikitaTheSpider.com/python/shm/

--
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
Feb 14 '08 #4
Nikita the Spider wrote:
In article <Ko************ *************** ***@comcast.com >,
Jeff Schwab <je**@schwabcen ter.comwrote:
>greg wrote:
>>Carl Banks wrote:
In C you can use the mmap call to request a specific physical location
in memory (whence I presume two different processes can mmap anonymous
memory block in the same location)
Um, no, it lets you specify the *virtual* address in the process's
address space at which the object you specify is to be mapped.

As far as I know, the only way two unrelated processes can share
memory via mmap is by mapping a file. An anonymous block is known
only to the process that creates it -- being anonymous, there's
no way for another process to refer to it.
On POSIX systems, you can create a shared memory object without a file
using shm_open. The function returns a file descriptor.

Sorry I missed the OP, but you might be interested in this shared memory
module for Python:
http://NikitaTheSpider.com/python/shm/

Thanks; I just downloaded it. It seems to be missing the INSTALL file;
any idea where I could find that, or should I write to the author?
Feb 14 '08 #5
In article <C5************ *************** ***@comcast.com >,
Jeff Schwab <je**@schwabcen ter.comwrote:
Nikita the Spider wrote:
In article <Ko************ *************** ***@comcast.com >,
Jeff Schwab <je**@schwabcen ter.comwrote:
greg wrote:
Carl Banks wrote:
In C you can use the mmap call to request a specific physical location
in memory (whence I presume two different processes can mmap anonymous
memory block in the same location)
Um, no, it lets you specify the *virtual* address in the process's
address space at which the object you specify is to be mapped.

As far as I know, the only way two unrelated processes can share
memory via mmap is by mapping a file. An anonymous block is known
only to the process that creates it -- being anonymous, there's
no way for another process to refer to it.
On POSIX systems, you can create a shared memory object without a file
using shm_open. The function returns a file descriptor.
Sorry I missed the OP, but you might be interested in this shared memory
module for Python:
http://NikitaTheSpider.com/python/shm/


Thanks; I just downloaded it. It seems to be missing the INSTALL file;
any idea where I could find that, or should I write to the author?
The main author has been AWOL for some years now. I'm the current
maintainer. Sorry about the missing INSTALL file. Looks like I made
reference to it in the README but never created it. It installs with the
normal setup.py:

sudo python setup.py

I'll put out an updated package with an INSTALL file one of these days.
Thanks for pointing that out.

Cheers

--
Philip
http://NikitaTheSpider.com/
Whole-site HTML validation, link checking and more
Feb 14 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2261
by: sr | last post by:
I have this kind of a code. It is from a book Linux programming, unleashed. I am not able to make to work so that, when it is run in two different xterm windows, the two different processes would affect to each others. /* shared_mem.c * Copyright Mark Watson 1998. Open Source Software License *
26
9313
by: myeates | last post by:
Hi Anyone ever done this? It looks like Python2.4 won't take a length arg Mathew
13
3511
by: George Sakkis | last post by:
I've been trying to track down a memory leak (which I initially attributed erroneously to numpy) and it turns out to be caused by a memory mapped file. It seems that mmap caches without limit the chunks it reads, as the memory usage grows to several hundreds MBs according to the Windows task manager before it dies with a MemoryError. I'm positive that these chunks are not referenced anywhere else; in fact if I change the mmap object to a...
1
5465
by: James T. Dennis | last post by:
I've been thinking about the Python mmap module quite a bit during the last couple of days. Sadly most of it has just been thinking ... and reading pages from Google searches ... and very little of it as been coding. Mostly it's just academic curiosity (I might be teaching an "overview of programming" class in a few months, and I'd use Python for most of the practical examples to cover a broad range of programming topics, including the...
1
7822
by: Seisouhen | last post by:
Hi all, I am using mmap to obtain some space(mapped anonymously) and am giving the address of the assigned space to a struct pointer. Then I want to access a member of the struct that the pointer points to. The code is: //----begin struct foo{ int test; }foo; struct foo one,*one_ptr; one_ptr=mmap(NULL,sizeof(one),PROT_READ|PROT_WRITE,MAP_ANON,-1,0);
0
801
by: JKPeck | last post by:
According to the mmap.mmap 2.5 documentation, "Changed in version 2.5: To map anonymous memory, -1 should be passed as the fileno along with the length." I would like to use shared memory to communicate between two processes that otherwise have no way to communicate, but I couldn't find a way to share anonymous memory. (I can use file names agreed on by convention, but the file is really irrelevant, and I'd prefer to eliminate it.) Is...
0
2449
by: Akira Kitada | last post by:
Hi list, I was trying to build Python 2.6 on FreeBSD 4.11 and found it failed to build some of the modules. """ Failed to find the necessary bits to build these modules: _bsddb _sqlite3 _tkinter gdbm linuxaudiodev spwd sunaudiodev
0
1947
by: Akira Kitada | last post by:
Hi Marc-Andre, Thanks for the suggestion. I opened a ticket for this issue: http://bugs.python.org/issue4204 Now I understand the state of the multiprocessing module, but it's too bad to see math, mmap and readline modules, that worked fine before, cannot be built anymore.
0
1811
by: M.-A. Lemburg | last post by:
On 2008-10-25 20:19, Akira Kitada wrote: Thanks. The errors you are getting appear to be related to either some missing header files or a missing symbol definition to enable these - looking at the ticket, you seem to have resolved all this already :-)
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8611
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8904
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8876
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7741
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.