-
[Linux Kernel] Device Driver : proc file system프로그래밍/리눅스 시스템 2024. 4. 29. 05:32
- proc file system 생성
- $ make 명령어를 통해 build하고, insmod 한다. => 커널 로그에 [init] HI 출력됨.
- $ ls –al /proc/ | grep pc 명령어를 통해 생성된 pc (proc fiile system)를 확인한다.[Makefile]
KERNEL_HEADERS=/lib/modules/$(shell uname -r)/build obj-m := pc.o total : driver driver: make -C $(KERNEL_HEADERS) M=$(PWD) modules clean: make -C $(KERNEL_HEADERS) M=$(PWD) cleancopy
[pc.c]
#include <linux/module.h> #include <linux/printk.h> #include <linux/init.h> #include <linux/proc_fs.h> #include <linux/seq_file.h> MODULE_LICENSE("GPL"); static struct proc_dir_entry *dir; static struct proc_dir_entry *file; static int pc_open(struct inode *inode, struct file *filp){ pr_info("Open File\n"); return 0; } static int pc_release(struct inode *inode, struct file *filp){ pr_info("Close File\n"); return 0; } static const struct proc_ops fops = { .proc_open = pc_open, .proc_release = pc_release, }; static int __init pc_init(void){ dir = proc_mkdir("pc", 0); file = proc_create("file", 0666, dir, &fops); pr_info("[init] HI\n"); return 0; } static void __exit pc_exit(void){ proc_remove(file); proc_remove(dir); pr_info("[exit] BYE!\n"); } module_init(pc_init); module_exit(pc_exit);copy
'프로그래밍 > 리눅스 시스템' 카테고리의 다른 글
[Linux Kernel] Device Driver : 묘듈 분할 (0) 2024.04.29 [Linux Kernel] Device Driver : Timer (0) 2024.04.29 [Linux Kernel] Device File : Read, write (with ioctl) (0) 2024.04.29 [Linux Kernel] Device Driver 적재, Device File 생성 (0) 2024.04.29 [Linux] 멀티 Process, Signal, WDT (0) 2024.04.15