而shmbuffer是struct shmid_ds (在/usr/include/sys/shm.h中),
裏面有些欄位來說明一下:
int shm_segsz: size of the shared memory
short shm_nattch: number of attaches to the segment
struct ipc_perm shm_perm:permission structure
而ipc_perm在/usr/include/sys/ipc.h中,裏面有些欄位是
unsigned short uid: identifier of the user of the segment
unsigned short mode : permission modes
key_t key(on linux is __key) : user-specified key identifier
下面是個簡單的實作範例:
#include
#include
#include
#include
int main(){
int segment_id;
struct shmid_ds shmbuffer;
segment_id = shmget(IPC_PRIVATE, 4096, S_IRUSR | S_IWUSR);
shmctl(segment_id, IPC_STAT, &shmbuffer);
printf("Seg ID\tKey\tMode\tOwner\tSize\tAttaches\n");
printf("%d\t%d\t%o\t%d\t%d\t%d\n", segment_id, shmbuffer.shm_perm.__key,
shmbuffer.shm_perm.mode, shmbuffer.shm_perm.uid, shmbuffer.shm_segsz,
shmbuffer.shm_nattch);
shmctl(segment_id, IPC_RMID, NULL);
return 0;
}
不過unix中有提供一個工具是ipcs就是類似這的output了,只是這裡寫的是極陽春版....
沒有留言:
張貼留言