pgrep returns nothing if the pattern length is longer than 15 characters. I can't find anything in the man page about maximum pattern length.

Is this a bug?

for purposes of exposition I created a process called 12345678901234567890

$ pgrep 12345678901234
$ pgrep 123456789012345
$ pgrep 1234567890123456

2 Answers 2


According to the pgrep man page (emphasis mine):


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?


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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .