The problem is that it is populating the script that i am executing as i pass the PID to the script the "ps" command wrongly thinks that the process exists when it does not.
Below is the out of my ps -ef | grep <PID> | grep -v grep command
In my opinion, if existence is all that's to be tested, this is by far the sanest suggestion in this thread. There's no point in generating extensive ps output only to search for something that was already known before ps was invoked (the pid).
radoulov's suggestion should be used, however, if what really matters is whether or not a process can be terminated by the effective user id running the shell script.
Regardless, there's no need for any ps | [grep | awk] pipelines.
please use correct syntax below may not be excat sytntax but u will get and idea
c=`ps -ef | grep exactprocessname | grep -v grep|wc -l`
if [ c -gt 0 && c -lt 1 ]
echo "process is running"
elif
if [ c -gt 1]
echo "multiple instances of process running"
else
echo "processs not running"
fi
That can't be used because what is given is the pid and not the process name. And, even if what was known were the process name, that approach leaves the door open to false positives, for example, if the process name matches a user name or an argument name, or matches some other field in the ps output. If process name were the key, pgrep is the best solution.
Since pid is reused, it is better to look for having a log file open using fuser. The pid could exit and the new pid assigned to another process of yours that has nothing to do with the application. Check not only the pid and user but the application, at least.