How to know if a background job is finished?
29,982
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!"
Related videos on Youtube
![San](https://i.stack.imgur.com/3Fwjr.jpg?s=256&g=1)
Author by
San
Updated on September 18, 2022Comments
-
San almost 2 years
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?
-
Manisankar about 9 yearsYou can use 'jobs' command to see the status of the process.. it will show the process ID and the current status..
-