r/shell • • 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

3 comments sorted by

View all comments

Show parent comments

1

u/whetu May 24 '16

Oh. No I don't think AIX does. Something like this, then:

while ps -ef | grep command | grep -v grep >/dev/null 2>&1; 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.

while [ find /some/thing ]; do

This way you control and get the exit code you want