Putting Jobs in the Background
Using nohup command &
is the way in which you start a job (command) which will not accept the hangup signal when you logout (nohup) and will run in the background (&).
Of course you need to remember to put nohup before your command and the & after your command. If you forget all is not lost you can do the same thing with the following commands: CTRL-z, fg, bg, jobs and disown.
- CTRL-z will put a process into the background and suspend it.
- fg [job id] will bring a process back to the foreground.
- bg [job id] will start a background job (note that it is still attached to your terminal and so will hang up if you logout)
- disown %[job id] will remove [job id] from the list of jobs you own which means that the job will continue to run after you logout.
- jobs will list the jobs you own.
- You can use job ids with commands like kill if you use the % i.e.
kill %[job id]
will kill [job id]. - The [job id] is not the process id.
- You can use job ids with commands like kill if you use the % i.e.
[1]+ Stopped ./test.sh
the above is the result of a CTRL-z the [job id] is the number in the square brackets.
So you will then need to start the job in the background with bg which outputs:
[1]+ ./test.sh &
Then disown process with disown %1
so you can logout