LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 10-19-2009, 05:26 AM   #1
hjc
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?
Code:
#include<stdlib.h>
#include<sys/shm.h>
#include<sys/stat.h>
#include<sys/ipc.h>



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');

  printf("key=%d\n",key);
  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("error");
  else{
    printf("success");
    //printf("Size=%d\n",buf.shm_segsz);                                                                                                                                         
            printf("Key=%d\n", buf.shm_perm.key);
  }       //Detach and remove the shared-memory //segment                                                                                                                           
              shmdt(shared_memory);
                    shmctl(segment_id,IPC_RMID,NULL);
  return 0;

}
 
Old 10-19-2009, 10:21 PM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Bookworm (Fluxbox WM)
Posts: 1,391
Blog Entries: 54

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
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 10:23 PM.
 
Old 10-20-2009, 01:16 PM   #3
hjc
LQ Newbie
 
Registered: Oct 2009
Posts: 8

Original Poster
Rep: Reputation: 0
thanks it works..
Quote:
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'.
 
  


Reply



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 06:16 AM
Key function changing squirrel001 Linux - Newbie 4 01-20-2009 06:50 PM
The function key for brightness up cz7asm Linux - Laptop and Netbook 0 11-09-2007 02:46 PM
shmctl IPC_RMID precludes further attachments? ta0kira Programming 17 08-07-2007 11:22 AM
Function Key eggoz Linux - Software 0 06-28-2006 08:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:59 PM.

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