2013年7月15日 星期一

[Kernel] 找出行程並傳送訊號

只是找一個 send_sig 的範例而已,找了半天看到不少範例,所以想做一個整理記錄,「如何在 Linux Kernel 中找出行程,並傳送訊號到這個行程」。這只是 Kernel 和 userspace 溝通的其中一個方法。

備註:
1. Kernel 版本間有差異,所以使用 task_struct 的方法不一樣。可以使用的方式計有:
a. for_each_process(task) { DO_SOMETHING; }

b. struct task_struct *task;
struct list_head *list;
list_for_each(list, &current->children) {
    task = list_entry(list, struct task_struct, sibling);
    DO_SOMETHING;
}

c. struct task_struct *task;
for (task = current; task != &init_task; task = task->parent) {
    DO_SOMETHING;
}

2. task->comm 定義 char 個數就只有 16 ,所以只能塞進 15 個字元。(還沒找到怎麼拿出行程全部名稱的方法,待查)
3. 送訊號使用 send_sig 來做。

參考資料:

沒有留言:

張貼留言