As I've learned from this question, [bracketed]
processes listed by the ps aux
command are kernel threads. So is there a way to kill them from the command line? If not, I guess the reason for that is to save the user from a higher risk of getting a kernel panic, right?
2 Answers
You can not kill kernel threads, or any process that is blocked in the D state, because signals are only delivered when the kernel returns to user mode. Aside from the technical limitation of signal delivery, killing a thread in the middle of kernel code would corrupt the system as the kernel code may be holding an important resource at the time, such as a spin lock or mutex, and killing it would prevent those resources from being released.
If you have a process that is stuck in the D state for a prolonged period of time, then you have a kernel bug. See https://wiki.ubuntu.com/KernelTeam/KernelTeamBugPolicies for tips on reporting it.

- 37,551
Kernel threads are necessary threads created by your Kernel to manage your system.
Not all are necessary but all (most) all beneficial and require mostly no extra resources, there is no reason why one would under normal conditions think about killing a Kernel thread.
Linux Kernel can create an destroy those threads when necessary, you should not worry about them and killing under most circumstances is not something you can do.

- 73,643
-
What if I have an thread which is in uninterruptable sleep which blocks a system resource like a device mounted with mount, or other hardware, which I want to release by killing the thread? – math Dec 12 '11 at 09:57
-
1File a bug against it if you think its useful (and not a glitch with your system) and hope that its solved soon. – Bruno Pereira Dec 12 '11 at 10:01
-
I would try to find out what is wrong with the mounting before deciding that killing kernel threads was the solution. – Bruno Pereira Dec 12 '11 at 10:27
-
I am not a kernel hacker but user of certain kernel drivers. Of course I should make a bug report if some device not working properly, but I have to wait then at least half a year, so next ubuntu brings this bugfix. I think that is a valid scenario and the linux kernel should come with the possibility to abort a certain action and release resources (if any were occupied). – math Dec 12 '11 at 10:37
-
you have unserstand that most likely the kernel thread was initiated by anogher process, so probably there is nothing wrong with that kernel thread except the process that started forgot to close it. i understand what you are saying but i dont think its even advisable to be killing kernel threads. – Bruno Pereira Dec 12 '11 at 10:47
-
Thanks for your comments, and by now I mostly agree with you, but could you give some facts why you don't think its not advisable to kill kernel threads? Is it that resources should not be managed by kernel threads but by the thread creator, or is this just experience or a feeling, or something else? Thanks. – math Dec 12 '11 at 10:55
-
You can not kill kernel threads, nor can you kill any process that is blocked in the D state ( until it unblocks ). – psusi Dec 12 '11 at 14:52
-
@psusi care to add an answer explaing why and where can we find more info on that? (thx for the comment) – Bruno Pereira Dec 12 '11 at 15:52