Search code examples
linuxbashpsgrep

Why can't pgrep find this process?


If I execute the following, which is just a long command that will wait forever

grep 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa abcd'

then pgrep -f can't find the process, if I search for abcd which is contained in the last segment of the long command.

ps auxww|grep abcd finds the process, but I can't use it in a script, as it also finds the grep process self.

If you remove just one a then pgrep -f abcd can find the process, but I have very long command with arguments, so I have run into this pgrep limitation.

Question

What is the correct way to check for such process based on the unique string abcd?


Solution

  • Your edited command is found by either of these commands:

    pgrep -f abcd
    

    or even:

    ps uxww | grep '[a]bcd'