Verify that the process is running without encountering a limit of 15 characters

3

With the following code we check if a certain process is running:

#!/bin/bash

#Verificar se processo abc está em execução
if pgrep "abc" >/dev/null 2>&1
  then
     printf "Está em execução.\n" >&2
  else
     printf "Não está em execução.\n" >&2
fi
exit

But if the process name is longer than 15 characters, for example abcdefghijklmnop , I will always get Não está em execução. because pgrep failed because of the 15-character limit coming from the size limit in the comm field of files in /proc/[pid]/stat .

Question

How can I refactor the code above to exceed the 15 character limit?

    
asked by anonymous 07.11.2014 / 18:34

1 answer

2

According to the notes in the pgrep manual you should use the -f option for the command .

  

The pattern is usually only compared to the process name. When -f is set, every command line is used in the comparison.

    
07.11.2014 / 19:14