Surviving logout: nohup, disown and tmux
Why closing a terminal kills your background jobs (SIGHUP) and three fixes: nohup before starting, disown after, and tmux to detach a whole session.
Job control: foreground and backgroundSignals and killRedirection
Surviving logout: nohup, disown and tmux
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Closing a terminal or dropping an SSH connection sends SIGHUP to the shell, and the shell passes it on to its jobs, which is why background work dies at logout.
- nohup CMD & starts a command that ignores SIGHUP. When its output goes to a terminal, nohup redirects it to nohup.out, so redirect it yourself to pick the file.
- disown removes a job from the shell's table so the shell will not hang it up. Use disown -h to keep it listed. This rescues a job you already started.
- tmux runs a persistent session on the machine. You detach and reattach, and the programs inside never see a hangup. It also keeps interactive programs and their screen.
- None of these restart a job after a reboot. For that you need a scheduler or a service manager.
The problem: jobs belong to a terminal
Job control has a catch. A job you background is still tied to the terminal that started it. When that terminal goes away, whether you closed the window or an SSH connection dropped, the kernel sends SIGHUP, “hangup”, to the shell. An interactive Bash forwards it to every job in its table, and each job dies. A background build is a letter you mailed through someone who tears it up when they leave the building.
There are three ways to break the tie. Each needs different timing: before you start, after you start, or by never depending on the terminal at all.
What actually happens
I tested it. In an interactive Bash 5.3 session on macOS I started four sleeping jobs, then killed the terminal (the pseudo-terminal behind the session) and listed processes a second later.
$ sleep 111 &
$ sleep 112 & disown
$ nohup sleep 113 > /dev/null 2>&1 &
$ sleep 114 &
$ disown -h %3
Afterwards pgrep -fl showed:
17154 sleep 112
17158 sleep 113
17162 sleep 114
The plain sleep 111 was gone. The disowned, nohuped and disown -h jobs all lived. Bash’s huponexit option is off, so typing exit normally would not have killed 111. Only a hangup does.
nohup: before you start
nohup runs a command with SIGHUP ignored:
$ nohup sleep 113 > /dev/null 2>&1 &
If you leave the output pointing at a terminal, nohup redirects it to a file called nohup.out, because the terminal will disappear. On macOS I got:
$ nohup echo hi
appending output to nohup.out
$ cat nohup.out
hi
GNU/Linux prints a longer message, nohup: ignoring input and appending output to 'nohup.out'. That is not an error. I did not run a GNU system, so take the wording from its documentation. Either way, choose your own destination with > file 2>&1 so you do not end up with a stray nohup.out in whatever directory you were in.
nohup only ignores hangup. kill PID still stops the command, as in the signals lesson.
disown: after you started
You forgot nohup and the job has run for an hour. Rather than restarting it:
$ sleep 112 & disown
disown removes the job from the shell’s table, so the shell has nothing to hang up. disown -h %3 keeps it listed in jobs but marks it “do not send SIGHUP”, which is what I used for 114. disown -a drops them all. A caveat from the test: disown -h takes the job number from jobs, and numbers shift as jobs come and go. My first attempt used %4, a job that did not exist, and the job it was meant to protect died with the terminal. Check jobs before you disown.
A disowned job’s output still points at the old terminal. If it printed there, the writes fail or vanish, so redirect first if you can.
tmux: don’t depend on the terminal at all
nohup and disown protect one command. tmux keeps a whole terminal alive on the machine, a session you detach from and reattach to later. That also covers programs that need a screen or your input. I started a detached session running a six-step loop and checked on it after the starting shell had gone:
$ tmux new-session -d -s build 'for i in 1 2 3 4 5 6; do echo "step $i"; sleep 1; done; sleep 600'
$ tmux ls
build: 1 windows (created Mon Nov 23 02:42:07 2026)
$ tmux capture-pane -p -t build
step 1
step 2
step 3
The tmux server is a separate process and the session’s programs are its children, not yours. Inside a live session, Ctrl-b then d detaches, tmux attach -t build returns, and over SSH the usual routine is: ssh, tmux new -s work, start the job, detach, log out, come back tomorrow. I ran the detached case above. I did not run an interactive detach and reattach through a real SSH connection.
Which one
- Starting a long, non-interactive command:
nohup cmd > out.log 2>&1 &. - Already started, no time to restart:
disown. - Interactive tools, or anything you want to inspect later:
tmux. - Needs to start at boot or restart on failure: none of these. That is a service manager’s job, covered with scheduling for time-based work and by
linuxfor services.
About the video
“’nohup: ignoring input and appending output to ‘nohup.out’’? Keep jobs running after logout” is a 9-minute video from Shell Stack, published in late October 2026. Its chapters follow this lesson closely: what the nohup message means, background jobs with & and jobs, Ctrl-Z with bg and fg, why jobs die at logout, fix 1 start it with nohup, finding your job after logging back in, fix 2 disown it, fix 3 tmux, common tmux errors and which to use. No other video I found covered nohup, disown and tmux together. I could not read a transcript or judge the teaching, and the channel is new, so this is a pick on scope and not on track record. It is in English. NormConf’s short talk on persistent SSH sessions with tmux is linked under deeper.
Where this fits
You can now keep work running past logout. The remaining case is work you want to start later, or on a schedule: cron and at.
Check yourself
You started a 3-hour download with a plain & and now need to close your laptop. What can you do without restarting it?
Run disown (or disown -h %N) in that shell, then close the terminal. The shell no longer sends it SIGHUP, so it keeps running, although its output may be lost if it was going to the terminal.
Why does nohup report 'appending output to nohup.out'?
Its output was a terminal, which will be gone after logout, so nohup redirected it to a file. Redirect output yourself with > file 2>&1 to choose where it goes.
When would you pick tmux over nohup?
When the program is interactive, or when you want to watch it later and send it input. nohup only protects a command from hangup, while tmux keeps the whole terminal.
Does nohup protect a job from kill PID?
No. It only makes the process ignore SIGHUP. SIGTERM and SIGKILL still work.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.