Thread: cannot read key when allocating shared memory

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    6

    cannot read key when allocating shared memory

    Hi,

    i wanted to read key in the ipc_perm struct using shmctl; during compilation i get this error message âstruct ipc_permâ has no member named âkeyâ
    Can anybody suggest?
    Code:
              #include<stdio.h>
    #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;
                                                                                                                                                      
      int shmctl_return;
      int size = 2048;
      char mode[3];
    
      key_t key;
    
    
       key = ftok("/home2/hrodriques/prog.c", 'R');
    
       printf("key=%d\n",key);
      segment_id= shmget(IPC_PRIVATE,size,S_IRUSR|S_IWUSR); //allocate a shared //memory segment                                                                                        
    
      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 memory //segment                                                                                              
      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);
    
         printf("Mode=%d\n",buf.shm_perm.mode);
    
        }       //Detach and remove the shared-memory //segment                                                                                                                         
                  shmdt(shared_memory);
                        shmctl(segment_id,IPC_RMID,NULL);
      return 0;
    }

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    The ipc_perm structure does not have a member named "key" according to Posix.
    <sys/ipc.h>

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with shared memory shmdt() shmctl()
    By Jcarroll in forum C Programming
    Replies: 1
    Last Post: 03-17-2009, 10:48 PM
  2. BSD mmap for shared memory - am I right?
    By sean in forum Linux Programming
    Replies: 21
    Last Post: 03-09-2009, 01:57 PM
  3. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  4. My Memory Game
    By jazy921 in forum C Programming
    Replies: 0
    Last Post: 05-05-2003, 05:13 PM
  5. FAQ: Directional Keys - Useing in Console
    By RoD in forum FAQ Board
    Replies: 38
    Last Post: 10-06-2002, 04:42 PM