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;
}