为以下代编写对应的makefile文件#include <linux/init.h> #include <linux/module.h> #include <linux/workqueue.h> #include <linux/sched.h> #include <linux/delay.h> #include <linux/timekeeping.h> MODULE_LICENSE("GPL"); static struct workqueue_struct* workqueue; static struct work_struct work1; static struct delayed_work work2; static int times; module_param(times, int, 5); int get_time(char* buff, int len) { struct timespec64 ts; struct tm tm_res; char time_string[40]; ktime_get_real_ts64(&ts); time64_to_tm(ts.tv_sec, 0, &tm_res); buff=tm_res.tm_year + 1900, tm_res.tm_mon + 1, tm_res.tm_mday,tm_res.tm_hour, tm_res.tm_min, tm_res.tm_sec; return 0; } static void real_time_work(struct work_struct* work) { char buff[40]; get_time(buff, sizeof(buff)); printk(KERN_INFO "%s\n",buff); } static void delayed_work(struct work_struct* work) { char buff[40]; get_time(buff, sizeof(buff)); printk(KERN_INFO "this is a delay work :%s\n", buff); } static int __init module_init(void) { printk(KERN_INFO "Initializing workqueue module.\n"); workqueue = create_workqueue("workqueue"); INIT_WORK(&work1, real_time_work); INIT_DELAYED_WORK(&work2, delayed_work); queue_work(workqueue, &work1); queue_delayed_work(workqueue, &work2, msecs_to_jiffies(10000)); return 0; } static void __exit module_exit(void) { printk(KERN_INFO "Exiting workqueue module.\n"); flush_workqueue(workqueue); destroy_workqueue(workqueue); } module_init(module_init); module_exit(module_exit);
时间: 2024-03-17 20:43:10 浏览: 161
如何编写makefile文件
4星 · 用户满意度95%
下面是对应的makefile文件:
```
obj-m := workqueue_module.o
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
```
请将上述代码保存为Makefile文件,并在代码所在目录下运行make命令,即可生成workqueue_module.ko文件。
阅读全文