Check if script is still running in bash

Hi Friends,

Have a script which invoke same shell script with different argument in background (usually runs couple of hours)

In above scenarios,
1. would like to check if all the above script execution has finished or not
2. In a loop with sleep/interval?
3. Once all finished, call a function and exit

I dont want to use sleep which increases the overall time for some reason in the script. Instead would like to use grep and check in a loop. pls help what is the best way to achieve this

ps -ef | grep  backgroundDummyProc | grep -v grep
if [ $? -eq 1 ]
    echo "Not running"
      echo "running"

Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Do you want those scripts to run in the background? Run them sequentially and the calling script will wait until the other completes before proceeding.

Without sleep, use a counter I.e. A for loop counting till 10000 between the ps check.

Check status, break out of loop if condition met
For counter
enthuguyAuthor Commented:
thx arnold

Run this in background as well
sample script pls

Just wondering what if it goes beyond 10000
#!/bin/bash \&
#if you want $! Is the PID of the command
While true; do
ps -ef |grep | grep -v grep
If test $? -eq 0; then
           echo running
           echo not
For ((i=0;i<=10000;i++)); do


Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
What are you after?
You have tasks that a script of yours trigger by cron scheduling or Anacron scheduling, etc.
And you want the same or aseparate script to report on when the scripts it triggers complete?
enthuguyAuthor Commented:
Thanks very much
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.