complete exercise source code

#include #include #include /* current and everything */#include /* printk() */#include /* everything... */#include /* size_t */#include MODULE_LICENSE("Dual BSD/GPL");static int complete_major = 253;//指定主设备号DECLARE_COMPLETION(comp);ssize_t complete_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_for_completion(&comp); printk(KERN_DEBUG "awoken %i (%s)/n", current->pid, current->comm); return 0; /* EOF */}ssize_t complete_write (struct file *filp, const char __user *buf, size_t count, loff_t *pos){ printk(KERN_DEBUG "process %i (%s) awakening the readers.../n", current->pid, current->comm); complete(&comp); return count; /* succeed, to avoid retrial */}struct file_operations complete_fops = { .owner = THIS_MODULE, .read = complete_read, .write = complete_write,};int complete_init(void){ int result;/* * Register your major, and accept a dynamic number */ result = register_chrdev(complete_major, "complete", &complete_fops); if (result < 0) return result; if (complete_major == 0) complete_major = result; /* dynamic */ return 0;}void complete_cleanup(void){ unregister_chrdev(complete_major, "complete");}module_init(complete_init);module_exit(complete_cleanup);Makefile:obj-m := complete.oKDIR := /lib/modules/$(shell uname -r)/buildPWD := $(shell pwd)default:$(MAKE) -C $(KDIR) M=$(PWD) modulesclean:rm -f *.ko *.o *.mod.c
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值