Linux设备驱动学习(3) 设备sleepy

本文介绍了一个在2.6.3x内核下编译通过的Linux设备驱动程序——sleepy。该程序在读取时将进程阻塞,写入时唤醒等待队列。测试过程包括查看主设备号、创建设备节点、读写操作。通过修改wait_event_interruptible()和wake_up_interruptible()为wait_event()和wake_up(),作者探讨了Linux中信号中断的概念,并观察到不可中断睡眠状态(D)。此外,文中还讨论了次设备号的灵活性以及程序潜在的竞态条件问题和解决策略。
摘要由CSDN通过智能技术生成

这个驱动程序可以在2.6.3x内核下编译通过。

sleepy是一个测试程序,当进程读设备时阻塞并进入等待队列,当写设备时则唤醒等待队列上的所有进程。


/*
 * sleepy.c -- the writers awake the readers
 *
 * Copyright (C) 2001 Alessandro Rubini and Jonathan Corbet
 * Copyright (C) 2001 O'Reilly & Associates
 *
 * The source code in this file can be freely used, adapted,
 * and redistributed in source or binary form, so long as an
 * acknowledgment appears in derived source files.  The citation
 * should list that the code comes from the book "Linux Device
 * Drivers" by Alessandro Rubini and Jonathan Corbet, published
 * by O'Reilly & Associates.   No warranty is attached;
 * we cannot take responsibility for errors or fitness for use.
 *
 * $Id: sleepy.c,v 1.7 2004/09/26 07:02:43 gregkh Exp $
 */

#include <linux/module.h>
#include <linux/init.h>

#include <linux/sched.h>  /* current and everything */
#include <linux/kernel.h> /* p
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值