• C

shmget() system call

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.
derick042497Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jos010697Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.