Linux share memory存取權限問題 - Linux
By Caitlin
at 2009-10-24T11:18
at 2009-10-24T11:18
Table of Contents
※ [本文轉錄自 C_and_CPP 看板]
作者: nagahara (Nagahara) 看板: C_and_CPP
標題: [問題] share memory存取權限問題
時間: Thu Oct 22 21:54:52 2009
有一個資料結構長這樣
typedef struct{
int head;
int tail;
int element_size;
void* array;
}Queue;
假設process A create一塊share memory是sizeof(Queue)+ARRAY_SIZE
這塊空間用一個Queue的指標接收:
Queue* queue = shmget(...);
queue->array指到queue下面多create出來的那塊空間:
queue->array = (char*)queue + sizeof(Queue);
Process A存取Queue都沒問題,
Process B用一個Queue*去get這塊空間之後,可以存取head tail element_size
但是要取array裡面的值時,卻得到亂碼,不然就會segment fault,
請問這是什麼原因呢? 要怎麼做才可以存取array的值呢? 謝謝
--
作者: nagahara (Nagahara) 看板: C_and_CPP
標題: [問題] share memory存取權限問題
時間: Thu Oct 22 21:54:52 2009
有一個資料結構長這樣
typedef struct{
int head;
int tail;
int element_size;
void* array;
}Queue;
假設process A create一塊share memory是sizeof(Queue)+ARRAY_SIZE
這塊空間用一個Queue的指標接收:
Queue* queue = shmget(...);
queue->array指到queue下面多create出來的那塊空間:
queue->array = (char*)queue + sizeof(Queue);
Process A存取Queue都沒問題,
Process B用一個Queue*去get這塊空間之後,可以存取head tail element_size
但是要取array裡面的值時,卻得到亂碼,不然就會segment fault,
請問這是什麼原因呢? 要怎麼做才可以存取array的值呢? 謝謝
--
Tags:
Linux
All Comments
By Candice
at 2009-10-27T04:53
at 2009-10-27T04:53
By Kelly
at 2009-10-30T20:03
at 2009-10-30T20:03
By Sandy
at 2009-11-04T05:26
at 2009-11-04T05:26
By Hazel
at 2009-11-07T17:54
at 2009-11-07T17:54
By Agnes
at 2009-11-08T09:06
at 2009-11-08T09:06
By Andrew
at 2009-11-09T10:36
at 2009-11-09T10:36
By Lydia
at 2009-11-11T21:21
at 2009-11-11T21:21
Related Posts
桌面用ubuntu,Server用CentOS?
By Jake
at 2009-10-24T02:11
at 2009-10-24T02:11
ubuntu 9.04 已經可以用Windows7了嗎?
By Leila
at 2009-10-24T00:27
at 2009-10-24T00:27
為什麼新增使用者到某特定群組後會出現錯誤?
By Oliver
at 2009-10-23T22:56
at 2009-10-23T22:56
桌面用ubuntu,Server用CentOS?
By Wallis
at 2009-10-23T20:37
at 2009-10-23T20:37
system(mv source dst)失敗
By Skylar Davis
at 2009-10-23T19:02
at 2009-10-23T19:02