Solved

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

Posted on 1998-05-27
6
222 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 44
Question regarding Copy/Paste 16 86
only14 challenge 19 63
modThree challenge 4 64
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. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now