Run Jobs That Survive Terminal Close: nohup and disown
Protect a background process from the SIGHUP that kills it when you exit the shell — no systemd unit required.
Run nohup ./long-job.sh > job.log 2>&1 & to start it immune to hangup, then disown -h %1 to also protect an already-running background job.
01Command
Command
$ nohup ./long-job.sh > job.log 2>&1 &
disown -h %102What it does
When a terminal closes, the shell sends SIGHUP to its jobs — the classic cause of 'my training script died when I closed the laptop'. nohup ignores that signal and redirects output away from the dying tty, while & puts the job in the background. disown -h %1 removes the job from the shell's job table (or just marks it no-hangup with -h), rescuing a process you already started without nohup.
03Risk
!Warning: nohup only shields SIGHUP: a reboot still kills the process. For anything that must auto-restart, use a systemd service instead.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- nohup(1) — Linux manual pageEvidence: nohup man page: 'run a command immune to hangups, with output to a non-tty' — SIGHUP immunity documented.
Last verified: 2026-09-17 · Category: Developer