Linux课程设计报告 编写proc文件系统相关的内核模块.docVIP

  • 109
  • 0
  • 约 7页
  • 2016-03-31 发布于江西
  • 举报

Linux课程设计报告 编写proc文件系统相关的内核模块.doc

Linux课程设计报告 编写proc文件系统相关的内核模块.doc

Linux课程设计报告 学院:信息学院 专业班级:08级网络二班 姓名: 学号: 【实验目的】 1.通过课程设计对操作系统基本原理进行更深入的认识,以Linux为具体研究对象,分析理解操作系统底层实现,综合利用已学知识与技术,就Linux操作系统各功能方面进行模拟或实现 2.了解内核模块结构 3.熟练内核模块编程,练习使用makefile 【实验要求】 编写proc文件系统相关的内核模块: 设计一个模块,该模块功能是列出系统中所有内核线程的程序名、PID号和进程状态。再设计一个带参数的模块,参数为进程的PID号,功能是列出进程的家族信息,包括父进程、兄弟进程和子进程的程序名、PID号。 【实验步骤】 编写list.c模块 编写Makefile make编译模块 安装模块sudo insmod list.ko 查看系统信息dmesg 退出模块sudo rmmod list 编写list2.c模块 编写Makefile make编译模块 安装模块sudo insmod list2.ko 查看系统信息dmesg 退出模块sudo rmmod list2 【代码实现】 1.list.c #include linux/kernel.h #include linux/module.h #include linux/proc_fs.h #include linux/init.h #include linux/sched.h #define METHOD 1 static int list_init(void) { struct task_struct *p; int count; char *method; count = 0; /*下面这些初始化完全是为了消除编译时的警告信息*/ p = NULL; method = NULL; method=for_each_process; printk( The method is %s\n, method ); printk(KERN_ALERT进程号\t父进程\t状态\t名称\n); #if METHOD == 1 for_each_process(p) { count++; printk( KERN_ALERT %d\t%d\t%ld\t%s\n, p-pid,p-parent-pid,p-state, p-comm ); } #endif printk(系统当前共 %d 个进程!!, count); return 0; } static void list_exit(void) { printk( KERN_ALERT GOOD BYE!!\n); } module_init( list_init ); module_exit( list_exit ); MODULE_AUTHOR( Along ); MODULE_LICENSE( GPL ); makefile ifneq ($(KERNELRELEASE),) obj-m := list.o else KERNELDIR ?= /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) default: $(MAKE) -C $(KERNELDIR) M=$(PWD) modules elean: rm -rf *.o *.mod.c *.ko *.syvmers endif 2.list2.c #include linux/kernel.h #include linux/module.h #include linux/proc_fs.h #include linux/init.h #include linux/sched.h #define METHOD 1 static int pidd = 1; module_param(pidd,int,S_IRUGO|S_IWUSR); EXPORT_SYMBOL(pidd); static int __init list_init(void) { struct task_struct *task, *p,*ppid; struct list_head *pos; int count; char *method; count = 0; /*下面这些初始化完全是为了消除编译时的警告信息*/ p = NULL; task = NULL; pos = N

文档评论(0)

1亿VIP精品文档

相关文档