概述
创建kernel thread时调用allow_signal指定它响应什么信号;
别处的内核代码可以: 用 kill_proc发送信号给它
- /*
- * file mythread.c
- */
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/init.h>
- #include <linux/param.h>
- #include <linux/jiffies.h>
- #include <asm/system.h>
- #include <asm/processor.h>
- #include <asm/signal.h>
- /*
- struct student {
- int age;
- char name[128];
- int score;
- };
- */
- static pid_t thread_id;
- struct completion exit_completion;
- int my_fuction(void *arg)
- {
- daemonize("demo-thread");
- allow_signal(SIGKILL);
- while(!signal_pending(current))
- {
- printk("jiffies is %lu/n", jiffies);
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(10 * HZ);
- }
- complete_and_exit(&exit_completion, 1);
- return 0;
- }
- static int __init init(void)
- {
- thread_id = kernel_thread(my_fuction, NULL, CLONE_FS | CLONE_FILES);
- return 0;
- }
- static void __exit fini(void)
- {
- kill_proc(thread_id, SIGKILL, 1);
- wait_for_completion(&exit_completion);
- printk("Goodbye/n");
- }
- module_init(init);
- module_exit(fini);
- MODULE_LICENSE("GPL");
最后
以上就是怕孤独果汁为你收集整理的用kernel_thread创建的内核进程,在内核中调用什么函数可以杀死这个进程的全部内容,希望文章能够帮你解决用kernel_thread创建的内核进程,在内核中调用什么函数可以杀死这个进程所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复