Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-19-2009, 06:26 AM   #1
LQ Newbie
Registered: Oct 2009
Posts: 8

Rep: Reputation: 0
not able to read key using shmctl function

i want to access the key value in struct ipc_perm using the shmctl function.

shmctl_return =shmctl(segment_id,IPC_STAT,&buf)

when i try to print contents of buf.shm_perm.key i get a message saying key is not defined in ipc_perm structure. can anybody help?

int main()

  char * shared_memory;
  int segment_id;
  struct shmid_ds buf;
  struct ipc_perm shm_perm;
  int shmctl_return;
  int size = 2048;

  key_t key;

  key = ftok("/home2/hrodriques/prog.c", 'R');

  segment_id= shmget(key,size,IPC_CREAT|S_IRUSR|S_IWUSR); //allocate a //sharedmemorysegment                                                                                      

  printf("SEGMENT ID = %d\n",segment_id);
  //Attach the shared-memory segment to its address //space.                                                                                                                        
  shared_memory=  (char *)shmat(segment_id,NULL,0);//atttach a shared //memorysegment                                                                                              
  if((shmctl_return =shmctl(segment_id,IPC_STAT,&buf))==-1)
            printf("Key=%d\n", buf.shm_perm.key);
  }       //Detach and remove the shared-memory //segment                                                                                                                           
  return 0;

Old 10-19-2009, 11:21 PM   #2
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Stretch (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
You need to use buf.shm_perm.__key. The ipc_perm you were using has been obsoleted, the new one is in 'include/bits/ipc.h'.

Last edited by neonsignal; 10-19-2009 at 11:23 PM.
Old 10-20-2009, 02:16 PM   #3
LQ Newbie
Registered: Oct 2009
Posts: 8

Original Poster
Rep: Reputation: 0
thanks it works..
Originally Posted by neonsignal View Post
You need to use buf.shm_perm.__key. The ipc_perm you were using has been obsoleted, the new one is in 'include/bits/ipc.h'.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
can't read from the device driver using read() function. parthi_s Linux - Newbie 1 03-23-2009 07:16 AM
Key function changing squirrel001 Linux - Newbie 4 01-20-2009 07:50 PM
The function key for brightness up cz7asm Linux - Laptop and Netbook 0 11-09-2007 03:46 PM
shmctl IPC_RMID precludes further attachments? ta0kira Programming 17 08-07-2007 12:22 PM
Function Key eggoz Linux - Software 0 06-28-2006 09:34 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:15 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration