Skip to content
# Process & service management

Running background jobs

Keep a command running after you disconnect with nohup, screen or tmux.

The problem

A command started over SSH is normally killed the moment your session disconnects (it receives SIGHUP). For anything that needs to keep running β€” a long import, a build, a script β€” you need one of the tools below.

Quick and dirty: & and nohup

& backgrounds a job for the current session only; it still dies if the SSH connection drops. nohup additionally ignores the hangup signal, so the process survives disconnection β€” but you lose the ability to reattach and watch it.

bash
./long-task.sh &            # background, dies on disconnect
nohup ./long-task.sh &      # survives disconnect
nohup ./long-task.sh > out.log 2>&1 &   # and capture its output

Reattachable: tmux

tmux (and the older screen) creates a persistent terminal session on the server that keeps running independently of your SSH connection β€” you can detach, log out, and reattach later exactly where you left off.

bash
sudo apt install tmux   # or dnf/zypper/pacman/apk install tmux
tmux new -s work        # start a named session
# run your command, then detach with: Ctrl-b then d
tmux attach -t work     # reattach later, from any SSH session
tmux ls                 # list sessions

For real services, use systemd instead

If something needs to run permanently (a web app, a bot, a queue worker), a systemd unit is the right tool, not a detached terminal β€” it restarts on crash and starts on boot automatically.

text
See "systemd & systemctl" for creating a .service unit.