Background Bash Script – Push bash script to background

Background Bash Script – Running a bash script in the background is a simple task using nohup, but what is less known is how to force an already running script to continue in the background freeing up your terminal for other tasks.

We have all had the situation with a chunky bash script running and you need to reboot your pc, or pop out of the office and dont want to leave the script running visible on your monitor. Whatever the reason, its something that is a useful took to have as and when you need it.

Just to cover the nohup option to START a script in the background you can do this –

nohup &

Ok so now for the main topic of this post which covers you if your script is ALREADY running, and you do not want to kill it, but force it to run in the background.

How to force your script to run in the background

Background Bash Script – There are 2 steps to achieve this –

1) First you need to ‘pause’ the running script. To do this press and z keys. This will stop the script from continuing but does NOT kill it.

2) Force the script to continue running in the background. To do this type in bg . The script will then continue as normal. You can even log out if you want and the script will still continue.

The other task you might then want to do is to bring the background job to the foreground. To do this just type fg and it will continue on your current session.