編寫proc文件系統(tǒng)相關的內核模塊設計_第1頁
編寫proc文件系統(tǒng)相關的內核模塊設計_第2頁
編寫proc文件系統(tǒng)相關的內核模塊設計_第3頁
編寫proc文件系統(tǒng)相關的內核模塊設計_第4頁
編寫proc文件系統(tǒng)相關的內核模塊設計_第5頁
已閱讀5頁,還剩2頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、linux課程設計報告 學院:信息學院 專業(yè)班級:08級網(wǎng)絡二班 姓名: 學號: 【實驗目的】1.通過課程設計對操作系統(tǒng)基本原理進行更深入的認識,以linux為具體研究對象,分析理解操作系統(tǒng)底層實現(xiàn),綜合利用已學知識與技術,就linux操作系統(tǒng)各功能方面進行模擬或實現(xiàn)2.了解內核模塊結構3.熟練內核模塊編程,練習使用makefile【實驗要求】編寫proc文件系統(tǒng)相關的內核模塊:設計一個模塊,該模塊功能是列出系統(tǒng)中所有內核線程的程序名、pid號和進程狀態(tài)。再設計一個帶參數(shù)的模塊,參數(shù)為進程的pid號,功能是列出進程的家族信息,包括父進程、兄弟進程和子進程的程序名、pid號?!緦嶒灢襟E】1. 編

2、寫list.c模塊2. 編寫makefile3. make編譯模塊4. 安裝模塊sudo insmod list.ko5. 查看系統(tǒng)信息dmesg6. 退出模塊sudo rmmod list7. 編寫list2.c模塊8. 編寫makefile9. make編譯模塊10. 安裝模塊sudo insmod list2.ko11. 查看系統(tǒng)信息dmesg12. 退出模塊sudo rmmod list2【代碼實現(xiàn)】 1.list.c#include #include #include #include #include #define method 1static int list_init(voi

3、d)struct task_struct *p;int count;char *method;count = 0; /*下面這些初始化完全是為了消除編譯時的警告信息*/p = null;method = null;method=for_each_process;printk( the method is %sn, method );printk(kern_alert進程號t父進程t狀態(tài)t名稱n);#if method = 1for_each_process(p) count+;printk( kern_alert %dt%dt%ldt%sn, p-pid,p-parent-pid,p-stat

4、e, p-comm );#endifprintk(系統(tǒng)當前共 %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 );makefileifneq ($(kernelrelease),) obj-m := list.oelse kerneldir ?= /lib/modules/$(shell una

5、me -r)/build pwd := $(shell pwd)default:$(make) -c $(kerneldir) m=$(pwd) moduleselean:rm -rf *.o *.mod.c *.ko *.syvmersendif2.list2.c#include #include #include #include #include #define method 1static int pidd = 1;module_param(pidd,int,s_irugo|s_iwusr);export_symbol(pidd);static int _init list_init(

6、void)struct task_struct *task, *p,*ppid;struct list_head *pos;int count;char *method;count = 0; /*下面這些初始化完全是為了消除編譯時的警告信息*/p = null;task = null;pos = null;method = null;task = &init_task;method=for_each_process;printk( the method is %sn, method );printk(kern_alert進程號t狀態(tài)t名稱t父進程t父進程名n);#if method = 1fo

7、r_each_process(p) count+;if (pidd = p-pid)printk( kern_alert %dt%ldt%st%dt%sn,p-pid,p-state,p-comm,p-parent-pid,p-parent-comm);ppid=p-parent;printk(兄弟進程名:t進程號:t 進程狀態(tài):tn);list_for_each_entry(ppid, &p-real_parent-children, sibling) printk( %s t%dt%ldtn,ppid-comm,ppid-pid,p-state); printk(子進程名:t進程號:t 進

8、程狀態(tài):tn);list_for_each_entry(ppid, &p-children, sibling) printk( %s t%dt%ldtn,ppid-comm,ppid-pid,p-state); #endifprintk(系統(tǒng)當前共 %d 個進程!, count);return 0;static void _exit list_exit(void)printk( kern_alert good bye!n);module_init( list_init );module_exit( list_exit );module_author( liyou );module_license( gpl );makefile _ifneq ($(kernelrelease),) obj-m := list2.oelse kerneldir ?= /lib/modules/$(sh

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論