- 论坛徽章:
- 0
|
最近在看ldd3, 看到complete的时候参考如下博客:
http://hi.baidu.com/phenix_yw/blog/item/4757f6243dcd83004c088dd9.html/cmtid/6ccf41df4bc1a01849540387
我的代码是complete.c:
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/sched.h>
- #include <linux/kernel.h>
- #include <linux/fs.h>
- #include <linux/types.h>
- #include <linux/completion.h>
- MODULE_LICENSE("Dual BSD/GPL");
- static int complete_major = 0;
- struct completion comp;
- DELCARE_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;
- }
- 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;
- }
- struct file_operations complete_fops = {
- .owner = THIS_MODULE,
- .read = complete_read,
- .write = complete_write,
- };
- int complete_init(void)
- {
- int result;
- result = register_chrdev(complete_major, "complete", &complete_fops);
- if (result < 0)
- {
- return result;
- }
- if (complete_major == 0)
- {
- complete_major = result;
- }
- return 0;
- }
- void complete_cleanup(void)
- {
- unregister_chrdev(complete_major, "complete");
- }
- module_init(complete_init);
- module_exit(complete_cleanup);
复制代码
Makefile是 bj-m :=complete.o
- default:
- make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
- clean:
- make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
复制代码
编译成功后安装模块成功:- #cat /proc/modules |grep complete
- complete 1936 0 - Live 0xf8202000
复制代码
但是再开一个终端尝试执行cat completion的时候却失败拉。。。说:
- #cat completion
- cat: completion: No such file or directory
复制代码
请问有人遇到过这种情况吗?谢谢 |
|