I'm completing an assignment which is about realize a pstree
command on Linux,my basic idea is to Traverse the files in the /proc
directory and look through the /proc/pid/status
and /proc/pid/task
to see the relationships between different processes,however,when i traverse the files,i notice that some processes are not showing up on the shell after pstree
command,i don't how to solve this
for example:/proc/2/status
is:
Name: kthreadd
Umask: 0000
State: S (sleeping)
Tgid: 2
Ngid: 0
Pid: 2
PPid: 0
....
but i use command pstree -p|grep kthreadd
,the pstree
command couldn't find the kthreadd
processes
All kernel threads are descendants of kthreadd (pid 2), which is spawned by the kernel (pid 0) during boot. The kthreadd enumerates other kernel threads; it provides interface routines through which other kernel threads can be dynamically spawned at runtime by kernel services. Kernel threads can be viewed from the command line with the ps -ef command--they are shown in [square brackets]:
As PID 2 is not a descendent of PID 1, it's not in the display of pstree.