2013-03-28 118 views
1

我正在linux-3.7.6/kernel/sched/core.c中,在schedule()函數中我必須記錄進程的pid和tgid,並且必須顯示記錄值給用戶空間。我在內核空間中使用了全局數組結構,我在其中存儲tgid和pid,我想如果我可以將數組地址傳遞給用戶空間,然後在用戶空間訪問tgid和pid的值。從內核空間傳遞地址到用戶空間

typedef struct process{ 
int pid; 
int tgid; 
}p; 

p proc[100]; 

有沒有一種方法可以將所有存儲在結構數組中的數據一次性發送到用戶空間? 我之前使用過copy_to_user,但只是在這裏卡住了,因爲如何發送這些整組值作爲copy_to_user以塊的形式複製數據?如果有人能夠告訴我如何繼續前進,我會非常感激。謝謝!

+0

使用網絡鏈路將此數據發送到用戶空間。 – 2013-03-28 15:09:58

+0

也許我錯了,但我從來沒有使用netlink之前,所以不知道我是否能夠正確實施它。你能否提出一些更幼稚的方法? – Vbp 2013-03-28 16:35:37

+0

好吧,改用內核到用戶的內存映射。 – 2013-03-28 16:39:02

回答

1

我假設你想保持原子性,同時將你的數組複製到用戶級別。

一個簡單的方法是:

p local_array[100]; 

preemption_disable(); //disable preemption so you array content will not change, 
         //because no schedule() can be executed at this time. 

memcpy(local_array, array, sizeof(array)); //then we get the consistent snapshot of 
              //array. 
preemption_enable(); 

copy_to_user(user_buff_ptr, local_array, sizeof(array)); 
+0

我一定會試一試。謝謝! – Vbp 2013-03-28 16:36:28

相關問題