Interview Prep/Shell Scripting/Shells, scripts and execution

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.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Shells, scripts and execution