Transferred from: http://blog.csdn.net/chinalinuxzend/article/details/4288791
[-]
- How to kill the D-state process ZT
- Related Posts
Original sticker: http://www.xclinux.cn/?p=752
How to kill the D status process? [ZT]
The status is D (uninterruptible sleep), and the status is Z (Zombie) These garbage processes are either begging or not, like a disgruntled woman waiting for resources (D), or stiff and immortal, waiting for the cross-over (Z) like ghost, they are stuck in the CPU run_queue, The Load Average the old high Old high, did not read my previous blog of the International friends also thought here resentment again what big thing. What to do? Shoot! kill-9! Let's see if you go. But the two kinds of garbage process is invulnerable, no matter what kind of marksmanship can not kill them. Helpless, had to reboot, like to destroy the avian flu as indiscriminately all culling!
The basic idea is to modify the kernel, traverse the list of processes, find a process in the D state, and convert its state to another state to kill it.
This is a rather rude method that may cause some undesirable consequences and is not considered for the time being. For the exact knowledge that there is no use, do not do clean-up work, in the D-state how to kill the process, is indeed very effective.
Kernel Module Code:
—————-KILLD.C —————-
#include <linux/init.h>
#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);
-–makefile ————
Obj-m: = KILLD.O
Compiling the module
Make-c yourkerneltree m= ' pwd ' modules
The process number of the D state is provided when the module is inserted, and it can be converted to the stopped state, which can be killed using normal kill.
./insmod./killd.ko pid=1234
How to kill the D status process? [ZT] "Turn"