🛡️ Command: nohup (No Hang Up)
The nohup command allows you to run a process that will keep running even after you log out of your session or close your terminal. It effectively "divorces" the process from your current terminal's lifecycle.
1. The "Why"
For an Arch Linux developer working on long-running tasks, nohup is a life-saver:
- Remote Work: If you are SSHing into another machine and your internet connection drops,
nohupensures your task doesn't die. - Long Compilations: When building a large project or compiling a complex document that might take several minutes, you can start it with
nohup, close your laptop, and let the CPU finish the job. - Background Services: Run a local web server or a simulation script that needs to stay active while you go do something else.
2. How it Works
When you close a terminal, it sends a SIGHUP (Signal Hang Up) to all the processes started inside it. nohup tells the process to ignore that signal.
By default, since the terminal is gone, nohup redirects any output (that would normally go to your screen) into a file called nohup.out.
3. Basic Syntax
nohup [COMMAND] &
Note: The
&at the end is technically optional, but almost always used so that the command starts in the background and gives you your prompt back immediately.
4. Practical Examples for Your Workflow
A. Running a Long Java Build
If you’re building your Preader app and want to make sure it finishes even if you close the terminal:
nohup ./gradlew assembleDebug &
B. Running a Simulation Script
For your Quantum Computing research:
nohup python3 simulation_v2.py > simulation_results.log 2>&1 &
> simulation_results.log: Redirects normal output to your specific log file.2>&1: Redirects errors (stderr) to the same file.&: Puts it in the background.
C. Running a Script to Update your Documentation
nohup ./update_docs.sh &
5. Managing nohup Processes
Since the process is no longer tied to your terminal, you can't see it with the jobs command if you close and reopen the terminal. To find it later:
- Find the Process ID (PID):
ps -ef | grep "simulation_v2.py" - Stop it if needed:
kill [PID]
6. nohup vs. & vs. screen/tmux
| Method | Survives Terminal Close? | Survives Logout? | Best For |
|---|---|---|---|
command & |
No | No | Quick background tasks while you work. |
nohup command & |
Yes | Yes | One-off tasks that must finish. |
tmux / screen |
Yes | Yes | Full interactive sessions you can "re-attach" to later. |
7. Pro-Tips
- Output Location: If you don't have write permissions in the current folder,
nohupwill attempt to writenohup.outto your home directory ($HOME/nohup.out). - Arch Linux Context: If you are testing a script that modifies your Waybar or Hyprland environment and you want it to persist while you restart the compositor,
nohupcan be a quick hack (though systemd services orexec-oncein your config are better for permanent solutions). - Tutorial Writing: If you're teaching others how to run servers,
nohupis the simplest "entry-level" way to explain persistent processes before moving into complex tools like Docker or Systemd.
8. Summary Reference
| Goal | Command |
|---|---|
| Basic usage | nohup [cmd] & |
| Custom log file | nohup [cmd] > output.log & |
| Ignore all output | nohup [cmd] > /dev/null 2>&1 & |