Alternative bash script to check if a process is running
4 answers
Perhaps you can use it pgrep
for this?
From the man page :
pgrep looks at the currently running processes and lists the process IDs that match the selection criteria for stdout.
Example:
$> pgrep firefox | xargs -r kill -9
In this example, the pid of the process is used by the command kill
. The option -r
xargs
allows to execute the command kill
only if pid is present.
+2
source to share