nice
Overview
The nice
command runs a program with modified scheduling priority. It allows you to start a process with a different niceness (priority) value.
Syntax
nice [-n adjustment] command [args]...
Common Options
Option | Description |
---|---|
-n N |
Add N to niceness (default 10) |
--adjustment=N |
Same as -n N |
-h |
Display help |
-v |
Verbose mode |
--version |
Show version |
Nice Values
- Range: -20 to 19
- Lower values = higher priority
- Higher values = lower priority
- Default: 0
- Only root can set negative values
Key Use Cases
- Process prioritization
- Resource management
- Background tasks
- CPU scheduling
- Performance optimization
Examples with Explanations
Example 1: Basic Usage
nice command
Run command with increased niceness (+10)
Example 2: Specific Priority
nice -n 15 command
Run command with niceness 15
Example 3: Maximum Priority
sudo nice -n -20 command
Run command with highest priority
Understanding Output
- Command output as normal
- Error messages for:
- Permission denied
- Invalid adjustment
- Command not found
- Priority range errors
Common Usage Patterns
Lower priority task:
nice -n 19 backup.sh
Higher priority task:
sudo nice -n -10 critical_task
Check current nice value:
nice
Performance Analysis
- Priority impact
- CPU scheduling
- System load effect
- Resource allocation
- Process behavior
Additional Resources
Best Practices
- Use appropriate values
- Monitor system impact
- Document priorities
- Consider dependencies
- Regular review
Use Cases
- Batch processing
- System maintenance
- Background services
- CPU-intensive tasks
- Non-critical operations