Solved

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

Posted on 1998-05-27
6
227 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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

728 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