Original post: http://www.xclinux.cn /? P = 752
How to kill a process in the D state? [ZT]
The State is D (uninterruptible sleep), and the State is Z (zombie) these spam processes are either seeking and not allowed, like a grievance, waiting for resources (d), or freezing and not dying, wait for the superdegree (z) Like a ram user, and they will not be able to stay in the CPU run_queue, so that the load average will become old and old, international Friends who haven't read my previous blog thought it was another big event. What should I do? Shot! Kill-9! You are not leaving. However, these two types of spam processes are pervasive. No matter which method they are used, they cannot be killed. Helpless, so we had to reboot, like killing the bird flu, all indiscriminately!
The basic idea is to modify the kernel, traverse the process list, find the process in the D state, convert it to another State, and kill it.
This is a rude method, which may cause some adverse consequences and is not considered yet. It is very effective for processes that know exactly that they are no longer useful and do not need to be cleaned up.
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
Compilation Module
Make-C yourkerneltree M = 'pwd' modules
When the module is inserted, a process number in the D State is provided, which can be converted to the stopped state and killed by using a common kill command.
./Insmod./killd. Ko pid = 1234