Linux Terminal Command: nohup
The nohup command is an essential tool in Process & Job Control. In this tutorial, we will explore what nohup does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The nohup command runs processes ignoring the SIGHUP (Hangup) signal, ensuring that background tasks continue running even if you close the terminal or log out.
Common Options & Syntax
nohup [options] [arguments]
Here are the most common flags used with nohup:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
nohup python3 script.py &
What it does: Runs ‘script.py’ in the background, redirecting stdout to ’nohup.out’ and ignoring shell hangups.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
nohup ./server > server.log 2>&1 &
What it does: Runs the server, redirects both output and error streams to ‘server.log’, and executes in the background.
⚙️ Warning & Common Pitfalls
[!WARNING]
nohupdoes not automatically run commands in the background. You must append&to the end of the command to send it to the background.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out: