How to use nohup and disown for background jobs
· Category: Linux
Short answer
nohup and disown allow processes to continue running after the terminal session ends.
Steps
- Run with nohup:
nohup ./long-running-script.sh > output.log 2>&1 &
- Disown an already running job:
./script.sh &
disown
- Background a job:
Ctrl+Z
bg
Tips
nohupredirects output tonohup.outby default.disown -hprevents SIGHUP without removing the job from the shell.- Use
screenortmuxfor interactive long-running sessions.
Common issues
- Forgetting to redirect output can fill the terminal buffer.
- Jobs started without
nohupmay still receive signals after disown.