为什么我不能pgrep一个进程?


12
$ ps aux | grep -i ssh
USER      4364  0.0  0.0   9004  1032 ?        Ss   12:20   0:00 ssh -v -fND localhost:4000 USERNAME@SERVER-IP-ADDRESS

$ pgrep localhost:4000

为什么不起作用?

Answers:


25

默认情况下,pgrep(1)将仅与进程名称匹配。如果要与完整的命令行匹配,请使用以下-f选项:

$ pgrep -f localhost:4000

8

看看pgrep手册页。它不仅是使用一堆列运行ps然后对文本输出进行greps的别名。它实际上在特定字段中搜索值。默认情况下,它仅在搜索时查看进程名称并返回PID。您可以通过添加-f选项来搜索完整的命令行。您还可以搜索其他可能有用的字段,例如匹配运行进程的终端或组ID。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.