2
我在內核中有一個模塊,其中在特定事件/計數中,我想喚醒用戶線程,它將通過proc fs從內核模塊讀取一些數據。什麼是從內核模塊觸發用戶線程的最佳方式
我試圖從內核模塊發送一個RT信號給處於睡眠狀態的用戶線程。該信號將調用其處理程序,並將進一步從內核讀取數據/緩衝區並將其存儲到文件中。
我正在面對一些未知的問題,使用這種方法後,發送信號系統被絞死,一切都停止。
請告訴我,如果我使用正確的方法(使用信號)從內核模塊觸發用戶線程。如果它是正確的,那麼鎖定問題的根本原因是什麼。
是否有任何連擊方式可用於實現此功能...請建議/幫助。
內核模塊:
static int send_signal(int data)
{
int ret;
struct siginfo info;
struct task_struct *t;
/* send the signal */
memset(&info, 0, sizeof(info));
/* I have tried 44 and 30 but both are not working */
info.si_signo = sig_num;
info.si_code = SI_QUEUE;
info.si_int = data;
if (!g_user_pid) {
printk("error seding signal, pid is not configured");
return -EAGAIN;
}
rcu_read_lock();
t = pid_task(find_pid_ns(g_user_pid, &init_pid_ns), PIDTYPE_PID);
if (t == NULL) {
printk("invalid pid\n");
rcu_read_unlock();
return -EAGAIN;
}
printk("sending value %u to pid %d\n", info.si_int, (int)t->pid);
ret = send_sig_info(sig_num, &info, t); /* send the signal */
rcu_read_unlock();
if (ret < 0) {
printk("error sending signal\n");
return ret;
}
}
PS:我是從中斷上下文此功能。
謝謝! 你能解釋一下如何實現這樣的事情。或分享一個鏈接瞭解此.. –
@PankajGupta解釋如何從頭開始做這將需要一本書或更多。我建議你拿一本關於編寫Linux設備驅動程序的書。 – msw