如何在内核中唤醒和睡眠用户进程??(zt)

来源:互联网 发布:sql气压罐有效容积 编辑:程序博客网 时间:2024/06/10 23:02
你可以参考interruptible_sleep_on和wake_up_interruptible的代码实现对指定进程的睡眠与唤醒,
其中,使用interruptible_sleep_on将当前进程置入睡眠态和一睡眠进程管理队列中,该队列中的进程可被中断唤醒,wake_up_interruptible则唤醒睡眠进程管理队列中的进程。

下面是临时写的唤醒程序,供参考

#define __KERNEL__
#define MODULE

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/spinlock.h>

static inline struct task_struct *self_find_task_by_pid(int pid)
{
struct task_struct *p, **htable = &pidhash[pid_hashfn(pid)];
for(p = *htable; p && p->pid != pid; p = p->pidhash_next);
return p;
}

int init_module(void)
{
struct task_struct *p;
pid_t pid = 9999;/*需要你提供进程号*/

read_lock(&tasklist_lock);
p = self_find_task_by_pid(pid);
read_unlock(&tasklist_lock);

wake_up_process(p);/*唤醒*/
return 0;
}

int cleanup_module()
{
return 0;
}

原创粉丝点击