8

I invoke a script (do_something) in background via another script (do_manythings) as below.

nohup do_something &

How would I know in the parent script (do_manythings) that the job invoked (do_something) has been done?

1
  • 1
    You can use 'jobs' command to see the status of the process.. it will show the process ID and the current status..
    – Manisankar
    Commented May 14, 2015 at 23:55

3 Answers 3

12

If you want to fire off a background job, do some other stuff, then stop and wait for the background job to finish, you can do

nohup do_something &
pid=$!
...more stuff...
wait $pid

Alternatively, you can test for the job having exited like this:

nohup do_something &
pid=$!
...more stuff...
ps -p $pid > /dev/null
[ $? == 1 ] && echo "it's gone, buddy!"
0

You can also look for start-stop-daemon (examples in /etc/init.d/) if you want to use do_something as a daemon.

0

You could check

ps -ef | grep 'do_something

If the result shows up, your script is still running.

you could also run

ps -ef | grep 'your_user_name'

to check all active running jobs on your ID.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .