473,320 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

shared memory confusion

Jim
I'm using the shmop_* functions to create and access shared memory. I've
never used shared memory before, so I apologize if my reasoning is
completely off...

$shm_id = shmop_open(ftok(__FILE__, 'a'), "c", 0600, 32);

That works for the first process, but if I try to launch a second process it
gives me the warning "Unable to create or attach shared memory" and fails.

According to the PHP manual, the 'c' flag will create shared memory, or if
one with the same key already exists, then it will open it for read/write
access - so I'm not sure why doesn't work (should it?). The manual page
mentions the last two args should be zero if I'm opening an existing memory
segment, but I don't know if I'm opening an existing segment when I execute
that line.

According to one of the manual comments, I can determine whether the memory
segment has been allocated already using the 'ac' flag:

1) $shm_id = shmop_open(ftok(__FILE__, 'a'), 'ac', 0, 0);
2) if(!$shm_id){
3) $shm_id = shmop_open(ftok(__FILE__, 'a'), 'c', 0600, 32);
4) }

But what happens if there is a context switch immediately after line 2 has
finished executing? Then two processes could both end up executing line 3,
and I'll get that warning again. Should I just use a semaphore to make
this atomic?

( linux 2.6, php 4.3.8)
Jul 17 '05 #1
2 5361
Jim wrote:
$shm_id = shmop_open(ftok(__FILE__, 'a'), "c", 0600, 32);

That works for the first process, but if I try to launch a second process
it gives me the warning "Unable to create or attach shared memory" and
fails.

Maybe this is obvious...but did you close the shm before accessing it from
the second instance? Maybe it's locked?

HTH

C.
Jul 17 '05 #2
Jim
No, the first process doesn't close it until just before it exits, so the
shared memory should still be available.
I'm not sure what you mean by 'locked' - how could it be locked? All the
processes are running as the same user, so the permission 0600 shouldn't
deny the other processes access.

Jim

"Colin McKinnon" <co**************@andthis.mms3.com> wrote in message
news:ch*******************@news.demon.co.uk...
Jim wrote:
$shm_id = shmop_open(ftok(__FILE__, 'a'), "c", 0600, 32);

That works for the first process, but if I try to launch a second process it gives me the warning "Unable to create or attach shared memory" and
fails.

Maybe this is obvious...but did you close the shm before accessing it from
the second instance? Maybe it's locked?

HTH

C.

Jul 17 '05 #3

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

Similar topics

0
by: Srijit Kumar Bhadra | last post by:
Hello, Here is some sample code with pywin32 build 203 and ctypes 0.9.6. Best regards, /Srijit File: SharedMemCreate_Mutex_win32all.py # This application should be used with...
3
by: alanrn | last post by:
I would like to start a dialog on how to implement the equivalent functionality of UNIX shared memory in .NET. I work with a factory automation system. The bulk of the system is written in C/C++....
11
by: Michael Schuler | last post by:
The use of STL in shared memory poses a real problem since (non-smart) pointers are not allowed there. Is there any solution for containers in shared memory using smart pointers? Where can I...
1
by: myren, lord | last post by:
When I first discovered shared memory (between multiple processes) I immediately started thinking of how to build my own VM subsystem + locking mechanisms for a large single block of memory. This...
12
by: Jeremy | last post by:
Hi all, I'm getting very confused about how DB2 uses shared memory and I wonder if someone could clarify matters for me, please ? We are running 32bit DB2 V7.2 FP9 under AIX 4.3.3 on a machine...
5
by: Jim | last post by:
Hello, I have a broken server that we are going to be moving off to a new server with a new version of DB2 but here is what I have right now: RedHat 7.0 (2.2.24smp) DB2 v6.1.0.40 I am...
4
by: John | last post by:
Hi What is the difference between a public and a shared sub? Thanks Regards
4
by: herbert | last post by:
I am coding a dozen "background" realtime apps for factory automation in .NET 2.0. The apps need to share a common memory as there are lots of variables to be shared (and synchronized of...
3
by: Jeff | last post by:
....still new to vb.net and vs 2005 web applications. I remain confused about the "shared" variable/table designation and the difference between "public" etc. I wish to place an entire table from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.