Without the -f option pgrep attempts to match the pattern argument against the process name in /proc/pid/comm. As per man proc_pid_comm the comm file has a maximum length 1:
Strings longer than TASK_COMM_LEN (16) characters (including the terminating null byte) are silently truncated.
On a Ubuntu 24.04.2 LTS system with pgrep from procps-ng 4.0.4 attempting to use a pattern with a string longer than 15 characters reports the following helpful message (as well as no matches):
$ pgrep gnome-terminal-server pgrep: pattern that searches for process name longer than 15 characters will result in zero matches Try `pgrep -f' option to match against the complete command line.
Whereas using the -f option produces a match:
$ pgrep -f gnome-terminal-server 8814
This is the truncated name that pgrep searches for without the -f option:
$ cat /proc/8814/comm gnome-terminal-
And this the complete command line searched when the -f option is used:
$ cat /proc/8814/cmdline /usr/libexec/gnome-terminal-server
1 On a 6.8.0-60-generic Kernel I noticed that Kernel threads can have a comm file with more than 15 characters, which pgrep can then find with the full name without needing to use -f. E.g.:
mr_halfword@Haswell-Ubuntu:~$ cat /proc/7741/comm kworker/u25:1-flush-8:0 mr_halfword@Haswell-Ubuntu:~$ pgrep kworker/u25:1-flush-8:0 7741
I haven't investigated why Kernel threads don't have their name limited by TASK_COMM_LEN in the same way as user space processes.
flex_camera_luc. Now, of courseflex_camerahappens to be a substring of the former, and both grep and pgrep by default match on substrings too. Why it showsflex_camera_lucand notflex_camera_lucidis interesting, but it's likely just a 15 char limit [citation needed].flex_camera,flex_camera_lucandflex_camera_lucid.ps -ewill show matched characters in bold font, but it ouputs none.flex_camera_lucidwould be showing, sigh.