⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sleepy.c

📁 LINUX设备驱动程序第二版配套源码 LINUX设备驱动程序第二版配套源码 Alessandro rubini&Jonathan corbet著 中国电力出版社 魏永明 骆刚 姜君译 69元
💻 C
字号:
/* * sleepy.c -- the writers awake the readers * * Tested with 1.2 on the x86 * Tested with 2.0 on the x86, Alpha *********/#ifndef __KERNEL__#  define __KERNEL__#endif#ifndef MODULE#  define MODULE#endif#define __NO_VERSION__ /* don't define kernel_verion in module.h */#include <linux/module.h>#include <linux/version.h>char kernel_version [] = UTS_RELEASE;#include <linux/sched.h>  /* current and everything */#include <linux/kernel.h> /* printk() */#include <linux/fs.h>     /* everything... */#include <linux/types.h>  /* size_t */#include <asm/segment.h>#include "sysdep.h" /* count_t for portability 2.0/2.1 */int sleepy_major=0;struct wait_queue *wq = NULL; /* must be zeroed at the beginning */read_write_t sleepy_read (struct inode *inode, struct file *filp,                char *buf, count_t count){    printk(KERN_DEBUG "process %i (%s) going to sleep\n",           current->pid, current->comm);    interruptible_sleep_on(&wq);    printk(KERN_DEBUG "awoken %i (%s)\n", current->pid, current->comm);    return 0; /* EOF */}read_write_t sleepy_write (struct inode *inode, struct file *filp,                const char *buf, count_t count){    printk(KERN_DEBUG "process %i (%s) awakening the readers...\n",           current->pid, current->comm);    wake_up_interruptible(&wq);    return count; /* succeed, to avoid retrial */}struct file_operations sleepy_fops = {    NULL,          /* lseek */    sleepy_read,    sleepy_write,                   /* nothing more, fill with NULLs */};int init_module(void){    int result;    /*     * Register your major, and accept a dynamic number     */    result = register_chrdev(sleepy_major, "sleepy", &sleepy_fops);    if (result < 0) return result;    if (sleepy_major == 0) sleepy_major = result; /* dynamic */    return 0;}void cleanup_module(void){    unregister_chrdev(sleepy_major, "sleepy");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -