Solved

Same SV key_t for sem. and shared mem. OK?

Posted on 1998-05-27
6
225 Views
Last Modified: 2013-12-26
Can I use the same key_t to identify a semaphore
and a shared memory region, or do they come out
of a single, global namespace?
0
Comment
Question by:BillSeymour
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:kellyjj
ID: 1293801
I don't think you can do that.  However, even if you could I would not recommend it.  
0
 
LVL 2

Accepted Solution

by:
seedy earned 50 total points
ID: 1293802
Yes, you can.  They come from different namespace.


0
 

Author Comment

by:BillSeymour
ID: 1293803
Obviously, I can't judge the content of the answer.
(If I could, I wouldn't have needed to ask the question.)
Assuming that the answer is correct, it certainly gets
an A...it's exactly what I wanted to know.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 2

Expert Comment

by:seedy
ID: 1293804
Yes, you can judeg the content of the answer.  Here is the proof.
Put the following lines in a file, compile and run.
-- code start --
#include <stdio.h>
#include <sys/sem.h>
#include <sys/shm.h>

#define      MYKEY      0x1CD1

main()
{
      int shmid = -1, semid = -1;

      if ( (semid = semget(MYKEY, 2, IPC_CREAT|IPC_EXCL)) >= 0 )
            printf("Created Semaphore with KEY: %d\n", MYKEY);
      else
            perror("semaphore creation failed");

      if ( (shmid = shmget(MYKEY, 2, IPC_CREAT|IPC_EXCL)) >= 0 )
            printf("Created Shared-mem with key: %d\n", MYKEY);
      else
            perror("shared memory creation failed");

      if ( semctl(semid, 0, IPC_RMID) < 0)
            perror("semaphore - removal failed");
      if ( shmctl(shmid, IPC_RMID, (void *)NULL) < 0)
            perror("shared mem - removal failed");
}
-- code end--
0
 

Author Comment

by:BillSeymour
ID: 1293805
I've tested seedy's code on an Intel box running AIX 4.2,
and it works regardless of which object I create first.
That's not to say that it won't fail on SOME Unix box
(absence of evidence is not evidence of absence);
nevertheless, I'll add 50 points to the score if there's
a way for me to do that.  (The code implies a prediction,
and so the theory is falsifiable.  (Is there a smiley
for "egghead?")) --Bill

--Bill
0
 
LVL 2

Expert Comment

by:seedy
ID: 1293806
Majority of the features under unix are common or standard.  Going by that experience, I would say that this is expected to work on ALL UNIXs.  If it won't work, I would assume it to be mentioned in the man pages!

For example the man pages on Digital OSF1 4.0, AIX 4.1, SunOS 5.5.1 and HP-UX 10.10 for semget states:

A semaphore identifier and associated data structure [...]
are created for key if one of the following is true:
       o key is equal to IPC_PRIVATE
       o key does not already have a ***semaphore identifier*** associated with it

You want to give me more points?  You must be a generous person!  You can do this by creating a new dummy question - asking me to answer it and then award the points.







0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adapt this command to show who installed 29 111
sumNumber challenge 16 138
dog bark java program 15 109
moto 4g phone enable finger print 4 26
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question