tmux and nohup are both tools for keeping processes running after you disconnect from a terminal, but they serve different purposes. nohup is a simple command that prevents a single process from terminating when you close the terminal, while tmux is a terminal multiplexer that provides a full terminal environment with multiple windows, panes, and sessions that persist after disconnection. tmux offers more interactive features like reattaching to running sessions, while nohup is more minimalist and focused on a single task.
# tmux approach tmux new -s my-session # Run commands interactively, then detach with Ctrl+b d # nohup approach nohup long-running-command &
Both tmux and nohup solve the problem of keeping processes running when you disconnect from a terminal session, but they approach this problem from different angles and with different feature sets.
nohup (short for "no hangup") is a POSIX command that prevents processes from being terminated when the terminal session closes. When you run a command with nohup, it ignores the SIGHUP (signal hangup) signal that's sent to processes when you log out or close the terminal.
# Basic nohup usage nohup long-running-command & # Output is redirected to nohup.out by default # You can specify a different output file nohup command > output.log 2>&1 & # Check running processes ps aux | grep command-name
tmux is a terminal multiplexer that allows you to create multiple terminal sessions within a single window, detach from and reattach to these sessions, and organize your workspace with windows and panes.
# Start a new named session tmux new -s my-session # Detach from the session with keyboard shortcut # Press Ctrl+b followed by d # Reattach to the session later tmux attach -t my-session
Feature | tmux | nohup |
---|---|---|
Purpose | Terminal multiplexer with session management | Simple command to prevent process termination |
Interactive use | Yes - can reattach and interact with running sessions | No - runs in the background, no interactive access |
Multiple processes | Yes - can run multiple commands in different panes/windows | No - applies to a single command (though you can use multiple times) |
UI features | Status bar, window management, pane splitting, etc. | None - purely command-line |
Output access | View in real-time after reattaching | Written to a file (nohup.out by default) |
Complexity | Higher - more features, more to learn | Lower - simple, straightforward |
Use tmux when:
Use nohup when:
You can combine tmux and nohup in certain scenarios. For example, if you're running a long script inside tmux but want an extra layer of protection:
# Inside a tmux session nohup ./long_script.sh > script.log 2>&1 & # This gives you "double protection" - the process will continue even if: # 1. You detach from tmux # 2. The tmux server itself crashes or is terminated
Besides tmux and nohup, there are other tools for keeping processes running: