系统相关
首页 > 系统相关> > linux 使用set_task 杀死D状态进程

linux 使用set_task 杀死D状态进程

作者:互联网

如何杀死D状态进程

https://blog.csdn.net/VincentLuo91/article/details/72625446

#include <linux/init.h> 
#include <linux/kernel.h> /*Needed by all modules*/
#include <linux/module.h> 
#include <linux/sched.h> //for_each_process 
MODULE_LICENSE("BSD"); 
static int pid = -1; 
module_param(pid, int, S_IRUGO); 
static int killd_init(void) 
{ 
    struct task_struct * p; 
    printk(KERN_ALERT "killd: force D status process to death/n"); 
    printk(KERN_ALERT "killd: pid=%d/n", pid); 
    //read_lock(&tasklist_lock); 
    for_each_process(p){ 
        if(p->pid == pid){ 
            printk("killd: found/n"); 
            set_task_state(p, TASK_STOPPED); 
            printk(KERN_ALERT "killd: aha, dead already/n"); 
            return 0; 
        } 
    } 
    printk("not found"); 
    //read_unlock(&tasklist_lock); 
    return 0; 
} 
static void killd_exit(void) 
{ 
    printk(KERN_ALERT "killd: bye/n"); 
} 
module_init(killd_init); 
module_exit(killd_exit); 
obj-m := killd.o 
all :
    $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    $(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

sudo insmod ./killd.ko pid=1234

————————————————
版权声明:本文为CSDN博主「vincentluo91」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/VincentLuo91/article/details/72625446

标签:task,modules,pid,KERN,killd,set,linux,printk,include
来源: https://blog.csdn.net/xiaozhi_botton/article/details/114967980