当我键入ps -ef
时,会显示许多特殊的内核线程进程。
我对内核线程不感兴趣;我只对用户进程/线程感兴趣。
有什么方法可以隐藏内核线程吗?
发布于 2016-01-29 04:43:08
ps
输出可以以可能的方式进行过滤。要查看您的进程,可以通过用户/uid进行筛选。以下有关手册页--
U userlist Select by effective user ID (EUID) or name.
This selects the processes whose effective user name or ID is in userlist. The effective user ID describes the user
whose file access permissions are used by the process (see geteuid(2)). Identical to -u and --user.
-U userlist Select by real user ID (RUID) or name.
It selects the processes whose real user name or ID is in the userlist list. The real user ID identifies the user
who created the process, see getuid(2).
-u userlist Select by effective user ID (EUID) or name.
This selects the processes whose effective user name or ID is in userlist. The effective user ID describes the user
whose file access permissions are used by the process (see geteuid(2)). Identical to U and --user.
要识别内核线程还是用户线程,它可能取决于内核版本。在我的Ubuntu机器(3.5.0-30-generic)上,我可以通过排除k线程的子线程(pid =2)来排除内核线程。在2.6内核上,kthreadd的pid可能有所不同--但是,您可以只使用相关的pid。例如,要获得没有ppid =2的所有进程的列表,我需要这样做(对于向-o提供的选项,请检查手册页)
ps -o pid,ppid,comm,flags,%cpu,sz,%mem --ppid 2 -N
您也可以使用grep或awk过滤这些内容。另一种识别内核线程的方法(不使用ps)是检查/proc//map或/proc/cmdline是否为空-对于内核线程两者都是空的。您需要根权限才能做到这一点。
https://unix.stackexchange.com/questions/258448
复制相似问题