Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is kthreadd process and children and how it is different from init and children

I wanted to know what is kthread and why it does not take any memory and has no open files. I wrote some code which will simply print the PID of the currently running processes in a parent child tree format along with some additional information like used VMZ, RSS, threads, openfiles. All the children of the PID 2 named kthreadd did not have the VmSize and VmRSS in the /proc/[pid]/status file. the /proc/[pid]/fd did not contain any open files.

What are these processes, how they are different with normal processes spawned by init (PID 1). I read (in an old book) that the swapper will spawn init PID1 and all other process are children of PID 1. Definitely there is a different architecture behind this (Linux kernel 3.7.10.1-16) which I don't know, so another question is why PID 2 is a child of PID 0 and is not a child of PID 1 .

like image 231
phoxis Avatar asked Aug 01 '13 08:08

phoxis


1 Answers

Kernel threads are not children of init because they can be started before all the userspace processes.

They are typically used to manage hardware that's why they are directly handled by the kernel and have high priority.

For a process to be child of init it needs to be cloned from init and Kthreads aren't that's why their parent PID is 0 meaning "no-one".

like image 159
MSI Avatar answered Oct 20 '22 00:10

MSI