我在内核中有一个模块,其中在特定事件/计数时我想唤醒一个用户线程,该线程将通过 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:我从中断上下文中调用此函数。
另一种方法是通过内核模块创建设备文件。在驱动程序放入数据之前,从此文件中读取数据将被阻止。在这种情况下,用户空间应用程序可以打开并读取设备文件数据,而无需任何睡眠和捕获信号。
Update: Here http://www.linuxdevcenter.com/pub/a/linux/2007/07/05/devhelloworld-a-simple-introduction-to-device-drivers-under-linux.html?page=2您可以找到创建只读设备文件的示例。您应该在中添加等待逻辑hello_read_proc()
,这将生成用于读取的块。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)