首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >有什么方法可以隐藏内核线程不受ps命令结果的影响?

有什么方法可以隐藏内核线程不受ps命令结果的影响?
EN

Unix & Linux用户
提问于 2016-01-29 03:33:37
回答 1查看 5.3K关注 0票数 4

当我键入ps -ef时,会显示许多特殊的内核线程进程。

我对内核线程不感兴趣;我只对用户进程/线程感兴趣。

有什么方法可以隐藏内核线程吗?

EN

回答 1

Unix & Linux用户

回答已采纳

发布于 2016-01-29 04:43:08

ps输出可以以可能的方式进行过滤。要查看您的进程,可以通过用户/uid进行筛选。以下有关手册页--

代码语言:javascript
运行
复制
   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提供的选项,请检查手册页)

代码语言:javascript
运行
复制
 ps -o pid,ppid,comm,flags,%cpu,sz,%mem  --ppid 2 -N

您也可以使用grep或awk过滤这些内容。另一种识别内核线程的方法(不使用ps)是检查/proc//map或/proc/cmdline是否为空-对于内核线程两者都是空的。您需要根权限才能做到这一点。

票数 5
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/258448

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档