pgrep pattern length limit
Solution 1:
According to the pgrep
man page (emphasis mine):
Notes
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
.
The reason is that process names are limited to 16 bytes including the NULL termination byte. From the prctl
manpage:
PR_SET_NAME (since Linux 2.6.9)
Set the name of the calling thread, using the value in the location pointed to by
(char *) arg2
. The name can be up to 16 bytes long, including the terminating null byte. (If the length of the string, including the terminating null byte, exceeds 16 bytes, the string is silently truncated.)
See What is the maximum allowed limit on the length of a process name?
Solution 2:
I think it's not a limit on the pattern length in pgrep
itself, but a limit on the length of the comm (command) field in the /proc/[pid]/stat files (which is where the information in ps
comes from).
According to man proc
, the definitions for /proc/[pid]/stat come from /usr/src/linux/fs/proc/array.c so you would need to look there for a definitive answer.