Kill a process in the D state

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.