On Fri, Apr 15, 2022 at 09:47:11PM -0400, The Wanderer wrote:
On 2022-04-15 at 20:47, Greg Wooledge wrote:
On Sat, Apr 16, 2022 at 08:20:40AM +0800, wilson wrote:
ps -efw |grep $PS |grep -v grep
You're also going to exit your script with the exit status from that
last grep command. That's probably not what you want. If it's not,
then an explicit "exit 0" at the end might be a good idea.
Or, as another choice, you might want to exit with the exit status
of the *first* grep. In that case, switching them around would be
better:
ps -efw | grep -v grep | grep "$PS"
This would probably result in undesired behavior. I recognize this
pattern [...]
If all you want to do is to find out whether a process with PID "$PS"
is running, why not
ps --pid "$PS" > /dev/null 2>&1 && echo "yo"
or even perhaps
kill -0 "$PS" 2>/dev/null && echo "yo"
But yes, for the general pattern you are right.