?
Solved

shmget() system call

Posted on 1997-05-05
1
Medium Priority
?
1,100 Views
Last Modified: 2008-03-10
I'm facing another problem now. Does anybody have any idea what the Sun Solaris system library nsl (makefile usage -lnsl) is used for? If somebody do, what is the equivalent in the IBM AIX system?

I also have problems getting the shared memory id using the following code :

#define STKCODE_TBL_SHMKEY      7001L
#define STKCODE_HASHSIZE        ( 2 * 1773 )
#define STKCODE_LEN             6

typedef struct {
    char    stkcode [ STKCODE_LEN+1];
    int     key;   /* index to data              */
    int     next;  /* next entry having same hash value  */
} STKCODE_TBL;                              

int
attach_stkcode_shm ( )
{
  key_t         key;
  int           shmid;
/*  long                shmsz; */
  int           shmsz;

  key = (key_t) STKCODE_TBL_SHMKEY;
  shmsz = STKCODE_HASHSIZE  * sizeof ( STKCODE_TBL );
  if ( ( shmid = shmget (key, shmsz, SHM_RDONLY )) == -1 )    {
        perror ("shmget STKCODE_TBL ");
        return (-1);
  }
}

In order to get the makefile running, I'd removed the -lnsl option from the makefile in the IBM AIX. However, the system call to the shmget() function still fails.

The error message shown is as followed :

shmget STKCODE_TBL : No such file or directory

The ipcs command did show the shared memory segment was created successfully. However, I am unable to extract the shared memory id out. I hope somebody can help me out.
0
Comment
Question by:derick042497
[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
1 Comment
 
LVL 4

Accepted Solution

by:
jos010697 earned 180 total points
ID: 1250251
Given the output of perror, shmget most likely had set
errno to ENOENT, meaning that no such entry was found.
Are you sure key value 7001 is correct? Normally a key
is created using ftok() ...

You could try to bitwise-or the last parameter with the
IPC_CREAT flag. If shmget succeeds, you're sure that
the 7001 key did not exist ...

BTW, you don't need the nls archive; it's the Network Support
Libray; AIX carries all the functionality in its libc.a archive ...

kind regards,

Jos

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

752 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