0

#!/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)

I work on many different systems of various age. Need to know the backend name resolution system and what is covered by the name resolver. So I often use pgrep to find all dns related processes.

Appears to be a string length limit for pgrep?

rjt
  • 377

1 Answers1

2

As explained in man pgrep,

The process name used for matching is limited to the 15 characters present in the output of /proc/pid/stat. Use the -f option to match against the complete command line, /proc/pid/cmdline.

“systemd-resolved” has 16 characters, so it falls foul of this limit. If you run pgrep -f systemd-resolved you’ll find the process.

Stephen Kitt
  • 434,908