我们2.2.8-1ubuntu0.15在我们的 VPS 实例上运行 Apache 版本Ubuntu 8.04.4 LTS \n \l,正如我通过问这个问题确定的那样。
当我发出时pgrep apache2,我得到以下信息:
2691
24517
25330
25669
25672
25795
25796
25809
25825
26401
26402
Run Code Online (Sandbox Code Playgroud)
这是 11 个单独的实例apache2!这是正常的吗?如果没有,我该怎么办?
我用来pgrep查找正在运行的进程有一些单词
> pgrep -f "otp"
2345
2343
Run Code Online (Sandbox Code Playgroud)
识别了多个进程。命令行中还有另一个单词可以帮助我将确切的过程归零。所以,我想搜索两个术语,并且两个术语都应该在那里。不幸的是,我只看到 OR 组合的示例和帮助,如下所示:
> pgrep -f "otp|place1"
2345
2343
3632
Run Code Online (Sandbox Code Playgroud)
这是行不通的,因为它是一个 OR 条件。我的搜索模式中需要一个 AND 条件。
pgrep 参考: https: //linux.die.net/man/1/pgrep
模式:指定用于匹配进程名称或命令行的扩展正则表达式。
如何使用 pgrep 搜索 AND 组合而不是 OR 的两个单词?
这是一个非常奇怪的问题,关于使用 pgrep 搜索哪些 shell 进程正在运行与当前进程相同的脚本。
\n这是名为test.sh的测试脚本
\n#!/bin/bash\n\nfull_res=`pgrep -a -l -f \'test\\.sh\'`\n\nres=$(pgrep -a -l -f \'test\\.sh\' | cat)\n\necho "short result is $full_res"\n\necho "weird result is $res"\nRun Code Online (Sandbox Code Playgroud)\n输出为
\nsh test.sh &\n[1] 19992\n\xe2\x9e\x9c logs short result is 19992 sh test.sh\nweird result is 19992 sh test.sh\n19996 sh test.sh\n\n[1] + 19992 done sh test.sh\nRun Code Online (Sandbox Code Playgroud)\n我不知道这些声音从何19996 sh test.sh而来,尤其是在使用管道猫时。我相信这可能是 pgrep 实现的一个错误。
期待合理的解释
\n谢谢,
\n巴林
\n打字时pgrep wget,它显示进程ID10144
但是如何知道这个进程ID的细节是什么
只有当它的进程没有运行时,我才想在 puppet 中使用 exec
exec { "execute me":
onlyif => "pgrep -fc 'ruby execute.rb'",
command => "execute me",
}
Run Code Online (Sandbox Code Playgroud)
因此,在上述情况下,如果进程 'ruby execute.rb' 已经在运行,则 exec 不应作为
pgrep -fc 'ruby execute.rb' will return 1.
Run Code Online (Sandbox Code Playgroud)
然而
该命令似乎总是在 puppet 中运行。
在我的 linux 机器上,当我执行 pgrep -fc 'ruby execute.rb' 时,我总是得到大于 0 的值。
我的命令有问题吗?