为什么有些Linux进程不能使用pstree打印?

enyaitl3  于 2023-10-16  发布在  Linux
关注(0)|答案(1)|浏览(182)

我正在完成一个关于在Linux上实现pstree命令的作业,我的基本想法是遍历/proc目录下的文件,并查看/proc/pid/status/proc/pid/task之间的关系,但是,当我遍历文件时,我注意到有些进程在pstree命令后没有显示在shell上,我不知道怎么解决这个问题
例如:/proc/2/status是:

Name:   kthreadd
Umask:  0000
State:  S (sleeping)
Tgid:   2
Ngid:   0
Pid:    2
PPid:   0
....

但我使用命令pstree -p|grep kthreaddpstree命令无法找到kthreadd进程

8fq7wneg

8fq7wneg1#

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]:

Kernel threads
由于PID 2不是PID 1的后代,因此它不在pstree的显示中。

相关问题