?
Solved

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

Posted on 1998-05-27
6
Medium Priority
?
228 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

800 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