Professional Documents
Culture Documents
Nguyên Lý Hệ Điều Hành: Bài Tập Chương 2
Nguyên Lý Hệ Điều Hành: Bài Tập Chương 2
◼ lsmod
Hiển thị các modules đang được nạp trong kernel theo 3
cột
Tên module
Kích thước
Được sử dụng ở đâu
MODULE_LICENSE(“GPL”);
MODULE_DESCRIPTION(“My first kernel module”);
MODULE_AUTHOR(“Le Minh Tuan”); Lê Minh Tuấn ©2013
Working with Modules
obj –m += mymodule.o
KVERSION = $(shell uname –r)
all:
make –C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make –C /lib/modules/$(KVERSION)/build M=$(PWD) clean
◼ Viết module:
module entry point: tạo một danh sách liên kết chứa 5
phần tử birthday. Duyệt danh sách và hiển thị nội dung
từng phần tử trong kernel log buffer
module exit point: xóa toàn bộ các phần tử trong danh
◼ Hướng dẫn
LIST_HEAD(birthday_list);
//Khởi tạo biến danh sách liên kết birthday_list
◼ Hướng dẫn
INIT_LIST_HEAD(&person->list);
//Khởi tạo danh sách rỗng
list_add_tail(&person->list, &birthday_list);
//Thêm phần tử vào danh sách
◼ Thư viện
#include<linux/list.h> //linked list
#include<linux/types.h> //list_head structure