




已閱讀5頁,還剩4頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
新鄉(xiāng)學(xué)院計算機與信息工程學(xué)院實 驗 報 告課程名稱 操作系統(tǒng)原理 專 業(yè) 計算機科學(xué)與技術(shù) 班 級 3班 學(xué) 號 2013052701xx 姓 名 xxx 實驗成績 任課教師 xxx 2013年 12月 3日實驗名稱鏈表的應(yīng)用姓 名xxx成 績實驗地點A14-322實驗時間2013年12月 3日一、 實驗?zāi)康呐c要求實驗?zāi)康模哼M(jìn)一步熟悉linux中鏈表的應(yīng)用實驗要求:認(rèn)真二、 操作步驟1、編寫list.c文件代碼,代碼如下:#include #include #include #include MODULE_LICENSE(GPL);MODULE_AUTHOR(XIYOU);#define N 10/鏈表節(jié)點struct numlist int num;/數(shù)據(jù)struct list_head list;struct numlist numhead;/頭節(jié)點static int _init doublelist_init(void)/初始化頭節(jié)點struct numlist *listnode;struct list_head *pos;struct numlist *p;int i;printk(doublelist is starting.n);INIT_LIST_HEAD(&numhead.list);/建立N個節(jié)點,依次加入到鏈表當(dāng)中for (i = 0; i num = i + 1;list_add_tail(&listnode-list, &numhead.list);printk(Node %d has added to the doublelist.n, i + 1);/遍歷鏈表i = 1;list_for_each(pos, &numhead.list) p = list_entry(pos, struct numlist, list);printk(Node %ds data:%dn, i, p-num);i+;return 0;static void _exit doublelist_exit(void)struct list_head *pos, *n;struct numlist *p;int i;/依次刪除N個節(jié)點i = 1;list_for_each_safe(pos, n, &numhead.list) /為了安全刪除節(jié)點而進(jìn)行的遍歷list_del(pos);/從雙鏈表中刪除當(dāng)前節(jié)點p = list_entry(pos, struct numlist, list);/得到當(dāng)前數(shù)據(jù)節(jié)點的首地址,即指針kfree(p);/釋放該數(shù)據(jù)節(jié)點所占空間printk(Node %d has removed from the doublelist.n, i+);printk(doublelist is exiting.n);module_init(doublelist_init);module_exit(doublelist_exit);2編寫Makefile文件代碼,代碼如下:obj-m :=list.o #產(chǎn)生list模塊的目標(biāo)文件CURRENT_PATH :=$(shell pwd) #模塊所在的當(dāng)前路徑LINUX_KERNEL :=$(shell uname -r) #Linux內(nèi)核源代碼的當(dāng)前版本LINUX_KERNEL_PATH :=/lib/modules/$(shell uname -r)/build#Linux內(nèi)核源代碼的絕對路徑all:make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) modules #編譯模塊clean:make -C $(LINUX_KERNEL_PATH) M=$(CURRENT_PATH) clean #清理3、行編譯:在list.c和Makefile文件的當(dāng)前路徑執(zhí)行make命令。得到模塊文件。4、加載模塊:依然是在當(dāng)前路徑執(zhí)行insmod list.ko5、查看模塊列表:執(zhí)行命令lsmod6、卸載模塊:執(zhí)行命令rmmod list7、查看輸出信息:執(zhí)行tail 命令三、 實驗結(jié)果1. 在模塊文件list.c和Makefile當(dāng)前打開終端,輸入make 命令之后,所在的文件會編譯出其他文件rootlocalhost 桌面# ls123 list.ko list.o Makefile tools2.c list.ko.unsigned list.txt modules.order 第二個實驗list.c list.mod.c hellomod.c Module.symvers 第一個實驗list.c list.mod.o Makefile result2. 在運行插入模塊insmod 之后,出現(xiàn)執(zhí)行插入模塊操作后,再次查看模塊列表就會看到hellomod模塊存在。rootlocalhost 桌面# insmod list.korootlocalhost 桌面# lsmodModule Size Used bylist 792 0 3. 執(zhí)行卸載模塊命令后就會發(fā)現(xiàn)list 模塊從模塊列表中消失。rootlocalhost 桌面# lsmodModule Size Used byvfat 8575 0 fat 47049 1 vfatusb_storage 39108 0 fuse 56800 2 4. 執(zhí)行dmesg命令可以看到輸出信息。usb 2-1.1: new high speed USB device number 4 using ehci_hcdusb 2-1.1: New USB device found, idVendor=0951, idProduct=1643usb 2-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3usb 2-1.1: Product: DataTraveler G3usb 2-1.1: Manufacturer: Kingstonusb 2-1.1: SerialNumber: 001CC05FE932FB90A92B25A0usb 2-1.1: configuration #1 chosen from 1 choicescsi5 : SCSI emulation for USB Mass Storage devicesusb-storage: device found at 4usb-storage: waiting for device to settle before scanningusb-storage: device scan completescsi 5:0:0:0: Direct-Access Kingston DataTraveler G3 1.00 PQ: 0 ANSI: 0 CCSsd 5:0:0:0: Attached scsi generic sg1 type 0sd 5:0:0:0: sdb 15644912 512-byte logical blocks: (8.01 GB/7.45 GiB)sd 5:0:0:0: sdb Write Protect is offsd 5:0:0:0: sdb Mode Sense: 0b 00 00 08sd 5:0:0:0: sdb Assuming drive cache: write throughsd 5:0:0:0: sdb Assuming drive cache: write through sdb: sdb1sd 5:0:0:0: sdb Assuming drive cache: write throughsd 5:0:0:0: sdb Attached SCSI removable diskSELinux: initialized (dev sdb1, type vfat), uses genfs_contextsusb 2-1.1: USB disconnect, device number 4No module found in objectdoublelist is starting.Node 1 has added to the doublelist.Node 2 has added to the doublelist.Node 3 has added to the doublelist.Node 4 has added to the doublelist.Node 5 has added to the doublelist.Node 6 has added to the doublelist.Node 7 has added to the doublelist.Node 8 has added to the doublelist.Node 9 has added to the doublelist.Node 10 has added to the doublelist.Node 1s data:1Node 2s data:2Node 3s data:3Node 4s data:4Node 5s data:5Node 6s data:6Node 7s data:7Node 8s data:8Node 9s data:9Node 10s data:10Node 1 has removed from the doublelist.Node 2 has removed from the doublelist.Node 3 has removed from the doublelist.Node 4 has removed from the doublelist.Node 5 has removed from the doublelist.Node 6 has rem
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年四川省西南醫(yī)科大學(xué)選調(diào)筆試真題
- 2024年四川阿壩師范學(xué)院選調(diào)筆試真題
- 2024年廈門銀行福建漳州分行招聘筆試真題
- 2024年莆田九十五醫(yī)院招聘筆試真題
- 2024年馬鞍山市福利院招聘筆試真題
- 2024年吉安縣農(nóng)業(yè)農(nóng)村局招聘筆試真題
- 行業(yè)最佳實踐分享與討論計劃
- 法學(xué)概論論文寫作指導(dǎo)試題及答案
- 信息處理技術(shù)員考題及答案收錄
- 2025屆江蘇省揚州市儀征市第三中學(xué)數(shù)學(xué)八下期末經(jīng)典模擬試題含解析
- 巴西詳細(xì)教案
- 基于PLC控制的物料分揀系統(tǒng)設(shè)計
- 上期開特下期出特公式
- 案件進(jìn)度管理規(guī)定表--執(zhí)行
- 人教部編版七年級歷史下冊教材插圖匯總
- 建筑工程竣工驗收報告山西
- 啟閉機房腳手架工程施工專項方案
- 變更監(jiān)事模板
- 前部分拼音四聲調(diào)
- 標(biāo)準(zhǔn)工程量清單細(xì)目編號公路工程
- 股東大會律師見證的法律意見書范本
評論
0/150
提交評論