#include <linux/wait.h>
#include <linux/poll.h>
static DECLARE_WAIT_QUEUE_HEAD(fortune_wait);
static unsigned int fortune_poll(struct file *file, poll_table *wait)
{
poll_wait(file, &fortune_wait, wait);
if (new-data-is-ready)
return POLLIN | POLLRDNORM;
return 0;
}
static const struct file_operations proc_test_fops = {
....
.poll = fortune_poll,
};
请注意,POLLIN | POLLRDNORM
如果您有一些新数据要读取,并且0
没有新数据要读取(poll()
呼叫超时),则应返回。有关详细信息,请参见man2民意调查。
wake_up_interruptible(&fortune_wait);
这是实现poll()
操作的基本内容。根据您的任务,可能需要在函数中使用一些waitqueue API.read
(例如wait_event_interruptible()
)。