Problem Statement
What is the purpose of the nohup command?
Explanation
Nohup (no hangup) runs a command immune to the HUP (hangup) signal, allowing it to continue running even after the terminal session ends or SSH connection drops. When you close a terminal, it normally sends SIGHUP to all child processes, terminating them. Nohup prevents this, making processes persist.
Syntax: nohup command & runs the command in the background, immune to hangups. By default, nohup redirects output to nohup.out in the current directory. Specify custom output: nohup command > custom.log 2>&1 & redirects both stdout and stderr to a custom log file. This is essential for long-running tasks on remote servers.
Nohup is commonly used for processes that must continue running after you log out, like data migrations, backups, batch processing, or monitoring scripts. For more advanced session management with the ability to reattach and view running processes, consider using screen or tmux instead of nohup.
Understanding nohup is crucial for DevOps and system administration, particularly when running maintenance tasks, deployments, or batch jobs on remote servers where network disconnections are possible. It ensures critical processes complete even if your SSH session is interrupted.
Practice Sets
This question appears in the following practice sets:
