static DECLARE_WAIT_QUEUE_HEAD(wq);
static int flag = 0;
ssize_t sleepy_read(struct file *filp, char __user *buf, size_t count, loff_t *pos)
{
printk(KERN_DEBUG, "process %i (%s) going to sleep \n",
current->pid, current->comm);
wait_event_inpterruptible(wq, flag != 0); //此时进程进入休眠,
//直到flag != 0 成立
flag = 0;
printk(KERN_DEBUG, "awoken %i(%s) \n", current->pid,
current->comm);
return 0;
}
ssize_t sleepy_write(struct *filp, const char __user *buf, size_t count, loff_t *pos)
{
printk(KERN_DEBUG, "process %i (%s) awakening reader ...\n",
current->pid, current->comm);
flag = 1;
wake_up_interruptible(&wq);
return count;
}
|