Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 1998-05-27
6
Medium Priority
?
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

609 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