473,787 Members | 2,932 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5397
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******** ***********@new s.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
4410
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 SharedMemAccess_Mutex_ctypes.py or SharedMemAccess_Mutex_win32all.py
3
2147
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++. It was ported from UNIX to run under Windows using .NET. If for no other reason than as an educational exercise, I have been wondering what it would take to rewrite the system under C#. The system currently has about a 100K “shared...
11
4905
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 find templates?
1
2117
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 seems like one option, the other appears to be just having each "object" you want to share be a shared mem space to itself: allocate objects into a defined shared mem space. But here you have many many objects being shared. Having a VM...
12
5546
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 with 64 Gb of memory with a single non-partitioned database using extended storage and with intra-parallelism enabled. I've been experimenting with changing various parameters in an attempt
5
7084
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 getting this error when I try to run the command 'db2 "backup database dbname online to /opt/BACKUP"' on my 3 databases: SQL1042C An unexpected system error occurred. SQLSTATE=58004
4
2035
by: John | last post by:
Hi What is the difference between a public and a shared sub? Thanks Regards
4
3117
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 course). I need distinct apps for reasons like user interaction/access rights, error compartments, and because the size of the code, access to various ports, ... In the end the apps should run as Windows Service(s).
3
2344
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 a DB into a datatable and then use it in a variety of different subs not unlike the code below. I'm not positive, but it seems that "shared" might also share the table across users, and this is not what I want. I only wish to be able to access...
0
9655
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
10363
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...
0
10169
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8993
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
5398
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...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.