nohup
Overview
The nohup
command runs a command immune to hangups, with output to a non-tty. It allows processes to continue running after the terminal is closed or the user logs out.
Syntax
nohup command [arguments]
Common Options
Option | Description |
---|---|
--help |
Show help |
--version |
Show version |
-p |
Print PID |
-u |
Unbuffered output |
Output Handling
File | Description |
---|---|
nohup.out | Default output |
~/nohup.out | Home directory |
./nohup.out | Current directory |
/dev/null | Discard output |
Key Use Cases
- Background jobs
- Long-running tasks
- Remote execution
- Batch processing
- System maintenance
Examples with Explanations
Example 1: Basic Usage
nohup command &
Run in background
Example 2: Custom Output
nohup command > output.log 2>&1 &
Redirect output
Example 3: Discard Output
nohup command >/dev/null 2>&1 &
No output file
Common Usage Patterns
Long process:
nohup ./script.sh &
With logging:
nohup command > log.txt &
Background job:
nohup command & echo $!
Process Management
- Background running
- Signal handling
- Output redirection
- Process isolation
- Job control
Additional Resources
Best Practices
- Redirect output
- Check process
- Use job control
- Monitor resources
- Clean up files
Security Considerations
- Process ownership
- File permissions
- Output handling
- Resource limits
- System access
Troubleshooting
- Process status
- Output files
- Permission issues
- Signal handling
- Resource usage
Common Issues
- Output location
- Process termination
- Signal handling
- File permissions
- Resource limits