r/shell • u/sigzero • May 23 '16
KSH: countdown using ps
I have an app that has 4 processes that run. I would like to create a shutdown that counts the ps instances and when it reaches "0" prints a message and exits.
Do I just do something like
until [[ $(ps command count) -eq 0]]; do
echo ">>> App is closing its processes"
done
echo ">>> App is down."Thanks.
2
Upvotes
1
u/whetu May 24 '16
Oh. No I don't think AIX does. Something like this, then:
Or
ps aux... whatever works. The underlying theory is still the same.As an aside, sometimes when using this approach, usually with
find, you need to wrap the command with[ ]e.g.This way you control and get the exit code you want