Check that process is running without bumping into the 15-character limit

Asked

Viewed 58 times

3

With the following code we check if a 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 has more than 15 characters, for example abcdefghijklmnop, I’ll always get Não está em execução. because the pgrep failure due to the 15 character limit from the size limit in the field with of the files in /proc/[pid]/stat.

Question

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

1 answer

2


According to the notes in the pgrep should be used the option -f for the command.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.