Chinaunix首页 | 论坛 | 博客
  • 博客访问: 85599
  • 博文数量: 17
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 125
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-28 17:19
文章分类

全部博文(17)

文章存档

2017年(5)

2015年(4)

2014年(8)

我的朋友

分类: LINUX

2014-09-16 17:30:07



#include
#include
#include
#include
struct proc_dir_entry *my_proc_info;
struct proc_dir_entry *show_my_proc_info;


int show_my_proc_func(char *page,char **start,off_t offset,int count,int *eof,void *data)
{
int len = 0;
len +=sprintf(page+len,">====Function: show my proc func=====<\n");
len +=sprintf(page+len,"hello ,you\n");
len +=sprintf(page+len,"hello ,my\n");
len +=sprintf(page+len,"hello ,proc\n");
len +=sprintf(page+len,"hello ,OK!\n");

return len;
}






static int __init my_proc_init(void)
{


my_proc_info = proc_mkdir("my_proc",NULL);
if(my_proc_info == NULL)
{
printk("can't create proc_dir my_proc!\n");
}
else
{
show_my_proc_info = create_proc_entry("show_my_proc_info",0666,my_proc_info);
if(show_my_proc_info)
{
show_my_proc_info->data = NULL;
show_my_proc_info->read_proc = show_my_proc_func;
}
else
{
printk("can't create proc dir show_my_proc_info!\n");
}
}

return 0;
}






static void __exit my_proc_exit(void)
{
if(my_proc_info != NULL)
{
if(show_my_proc_info != NULL)
{
remove_proc_entry("show_my_proc_info",my_proc_info);
}
remove_proc_entry("my_proc_info",NULL);
}

printk("Exiting module !\n");
}


module_init(my_proc_init);
module_exit(my_proc_exit);
MODULE_LICENSE("GPL");

阅读(1344) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~