hi
i've been toying around, started reading some books, and came upon a problem.
i'm trying to write a c program that will output some data about some shared memory segment, given that segment's numeric designation.
here's the code (without checkign and unneccesary parts...)
#include <stdio.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <ctype.h>
int main(){
int segment_id = 456456; /* let's asume i know the ID of the shared mem. segment */
struct shmid_ds buffer;
/* dovuci podatke o segmentu*/
if(shmctl(segment_id, IPC_STAT, &buffer) != 0){
printf("shit\n");
exit(-1);
}
printf("owner: %d\n", buffer.shm_perm.uid); /* ok*/
printf("size: %d \n", buffer.shm_segsz); /* NOT OK */
printf("# of attaches: %d \n", buffer.shm_nattch); /* NOT OK */
return 0;
}
Now, 2 questions:
- why do i get segmentation fault every time i run the prog? it runs it course, but always ends up with a segmentation fault
- when i try to access sub-structure shm_perm, all data is ok, but when i try to access any members of the shmid_ds structure, i get out garbage... why?
thank you
Shoki