![为什么 pgrep 找不到 systemd-resolved?](https://linux22.com/image/213511/%E4%B8%BA%E4%BB%80%E4%B9%88%20pgrep%20%E6%89%BE%E4%B8%8D%E5%88%B0%20systemd-resolved%EF%BC%9F.png)
#!/usr/bin/env bash
echo "pgrep not finding systemd-resolved has bitten many times."
if [ -z $(pgrep systemd-resolved) ]; then
echo -e "systemd-resolved not found by pgrep, trying another way.\n";
ps aux | egrep -i '(DNS|HOST|DH|RESOLV|systemd-resolved)' | egrep -v 'grep -E';
fi;
systemd-resolved not found by pgrep, trying another way:
systemd+ **914** 0.0 0.0 26196 4048 ? Ss Nov12 0:02 /lib/systemd/**systemd-resolved**
rjt 73300 0.0 0.0 9228 2160 pts/2 S+ 23:02 0:00 grep -E --color=auto -i (DNS|HOST|DH|RESOLV|systemd-resolved)
我在不同年龄的许多不同系统上工作。需要了解后端名称解析系统以及名称解析器涵盖的内容。所以我经常使用pgrep来查找所有与dns相关的进程。
似乎是 pgrep 的字符串长度限制?
答案1
正如中所解释的man pgrep
,
用于匹配的进程名称仅限于 输出中存在的 15 个字符
/proc/pid/stat
。使用该-f
选项来匹配完整的命令行,/proc/pid/cmdline
.
“systemd-resolved”有 16 个字符,所以它违反了这个限制。如果你运行pgrep -f systemd-resolved
你会找到该进程。