What are `nohup`, `disown` and `setsid` used for?
IntermediateConceptShells, scripts and execution
Answer
When a terminal closes, the shell sends SIGHUP to its jobs. nohup cmd & makes cmd ignore SIGHUP and redirects output to nohup.out. disown %1 removes a running job from the shell's job table so it is not sent SIGHUP. setsid cmd starts it in a new session with no controlling terminal.
For anything that must keep running, we do not rely on these: we use a systemd unit (systemd-run --unit=reindex ./reindex.sh for one-offs) or tmux, so the job is supervised and logged.
More on Shells, scripts and execution
What is a shell, and how is Bash different from sh, dash and zsh?BeginnerWhat does the shebang line do, and why prefer `#!/usr/bin/env bash` over `#!/bin/bash`?BeginnerWhat is the difference between `./script.sh`, `bash script.sh` and `source script.sh`?BeginnerWhat happens when you type a command name? How does Bash decide what to run?AdvancedWhy must `cd`, `export` and `read` be builtins rather than external programs?IntermediateWhat is the difference between a login, interactive and non-interactive shell, and which startup files run?Intermediate