Background Processes

Background processes allow you to run long-lived applications and services without occupying your terminal session. This is essential for development workflows where you need multiple services running simultaneously, such as development servers, Docker containers, or language model interfaces like Ollama. Rather than opening multiple terminal windows, you can use tmux (terminal multiplexer) to create detachable sessions that persist independently of your current shell.

Creating and Using tmux Sessions

To start a new tmux session, use tmux new -s <session-name>. This creates a named session where you can run commands as usual. Once inside the session, you can launch your process (such as [[entities/python|python]] script.py, [[entities/docker-desktop|docker]]-compose up, or ollama serve). To detach from the session and return to your main shell, press Ctrl+B followed by D. The process continues running in the background.

To reconnect to an existing session, use tmux attach -t <session-name>. You can view all active sessions with tmux list-sessions. If a session is no longer needed, terminate it with tmux kill-session -t <session-name>.

Practical Considerations

Using tmux is preferable to background operators like & or nohup because it preserves the full terminal environment and allows you to monitor output or interact with the process later. Each tmux session maintains its own shell state, so you can run multiple independent services simultaneously without conflicts. This approach is particularly useful when working over SSH connections, as tmux sessions persist even if your network connection drops.

Source Notes