Skip to content

How to move Unix script to run in background after it was started?

Say for example, you started nz_groom Netezza script and then want to move it to background so that you cna disconnect your session
without aborting the script.
Just follow below steps to make this happen:

1) Say, you have already started below script at command prompt
$->nz_groom DBName -records all

2) Now just issue [ ctrl + z ] to stop this job
[1]+ Stopped nz_groom DBName -records all

NOTE: THis step will just stop the job temporarily and will not abort/kill the job.

3) Now issue a command [ jobs ] to verify the curren tstatus of your script
[1]+ Stopped nz_groom DBName -records all

4) Issue a command [ bg ] to move this script to run in back ground
[1]+ nz_groom DBName -records all &

5) Again issue a command [ jobs ] to verify the curren tstatus of your script. This script will be running now in background.
[1]+ Running nz_groom DBName -records all &

6) Now issue a command [ disown ] to disconnect this job form your session

7) Now, if you run jobs you will not see any. BEcause its already disowned from your session

8) Just run [ ps -ef ] and you will see that job running in background just as it would have if you just run the job in background
at very first place.
$->ps -ef | grep nz_groom
nz 17348 30322 0 17:02 pts/1 00:00:00 grep nz_groom
nz 19605 23341 0 16:53 pts/1 00:00:00 /bin/sh /nz/support/bin/nz_groom DBName -records all
nz 23341 30322 0 14:03 pts/1 00:00:00 /bin/sh /nz/support/bin/nz_groom DBName -records all