Dan*_*ley 26
pgrep的输出选项非常有限。您几乎肯定需要将其发回ps以获取重要信息。您可以通过在 .bash 文件中使用 bash 函数来自动执行此操作~/.bashrc。
function ppgrep() { pgrep "$@" | xargs --no-run-if-empty ps fp; }
Run Code Online (Sandbox Code Playgroud)
然后调用命令。
ppgrep <pattern>
Run Code Online (Sandbox Code Playgroud)
nal*_*ply 18
结合pgrep与ps使用xargs!
pgrep <your pgrep-criteria> | xargs ps <your ps options> -p
Run Code Online (Sandbox Code Playgroud)
例如尝试
pgrep -u user | xargs ps -f -p
Run Code Online (Sandbox Code Playgroud)
获取完整的进程列表user。选项-u user限制pgrep给给定的用户(作为数字或名称),而ps选项-f -p请求所选 PID 的完整格式列表。
最好将第一行保留为列名。grep总是删除列名。
Ben*_*kin 12
下面只给你 PID + 完整的命令行。对于“所有信息ps都可以”,请参阅其他答案...
大多数 linux 使用procps-ng。从 3.3.4(2012 年发布)开始,pgrep -a( --list-full) 显示完整的命令行。
注意:默认情况下 pgrep 仅匹配您针对可执行文件名称提供的模式。如果要匹配完整的命令行(如 grepping ps 所做的那样),请添加-f( --full) 选项。
在旧版本(包括原始procps项目)中,-l选项显示信息,但其行为有所不同:
pgrep -fl 将模式与完整命令行匹配并显示完整命令行。pgrep -l单独匹配仅可执行名称并仅显示可执行名称。不确定 *BSD 使用什么代码,但他们的手册页记录了旧-fl行为。
不幸的是,你甚至不能-fl便携地使用——在最近的 procps-ng 中,-f( --list-name) 总是只打印可执行文件的名称。
对于 GNU 版本的pgreplong + 模糊输出是通过使用实现的,-af并且字符串必须区分大小写(即没有选项不区分大小写)。
$ pgrep -af apache
OUTPUT:
1748 /usr/sbin/apache2 -k start
Run Code Online (Sandbox Code Playgroud)
手册页:
-a, --list-full
List the full command line as well as the process ID. (pgrep only.)
-f, --full
The pattern is normally only matched against the process name.
When -f is set, the full command line is used.
Run Code Online (Sandbox Code Playgroud)
在 OSX 上(以及通过推断,在 BSD 上)-l(长输出)与-f(匹配完整参数列表)将显示完整的命令(-i添加不区分大小写):
$ pgrep -af apache
OUTPUT:
1748 /usr/sbin/apache2 -k start
Run Code Online (Sandbox Code Playgroud)
该手册页:
-a, --list-full
List the full command line as well as the process ID. (pgrep only.)
-f, --full
The pattern is normally only matched against the process name.
When -f is set, the full command line is used.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31571 次 |
| 最近记录: |