I use pgrep from procps-3.3.10.

If I have executable aout_abcdefgh_ver27, then

pgrep aout_abcdefgh_ver27

returns nothing, while ps aux | grep aout_abcdefgh_ver27 returns the expected result:

ps aux | grep aout_abcdefgh_ver27 
evgeniy  14806  0.0  0.0   4016   672 pts/8    S    12:50   0:00 ./aout_abcdefgh_ver27
evgeniy  15241  0.0  0.0  12596  2264 pts/8    S+   12:50   0:00 grep --colour=auto aout_abcdefgh_ver27

But if I run

$ pgrep aout_abcdefgh_v

pgrep returns what I expect, so I wonder why it works in such a strange way, maybe I should use some option for pgrep to work with full process name?

It looks like it has a very short limit for the pattern, something like ~ 10 symbols.

  • What is the command line you use to launch the process? Ideally, edit your question and show us the output of ps aux | grep a.out. – terdon Mar 2 '16 at 9:43
  • @terdon Thanks for comment, I update my question – fghj Mar 2 '16 at 9:54

The problem is that by default, pgrep only searches the process name. The name is a truncated version of the entire command. You can see what the name is by looking at /proc/PID/status where PID is the process ID of the relevant process. For example:

$ ./aout_abcdefgh_ver27 &
[1] 14255                    ## this is the PID
$ grep Name /proc/14255/status
Name:   aout_abcdefgh_v

So yes, pgrep with no flags only reads the first 15 characters of the executable's name. To search the full command line used to launch it, you need the -f flag (from man pgrep):

-f, --full
     The pattern is normally only matched against the process name.  
     When -f is set, the full command line is used.

So, if you use -f:

$ pgrep -f aout_abcdefgh_ver27 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.