nice — Run a command at a lower or higher priority in bash, zsh, fish, PowerShell, and cmd across all 5 shells
Equivalents in every shell
nice -n 10 ./long-running-job.sh`-n N` sets niceness from `-20` (highest priority) to `19` (lowest). Defaults to `10` (lower priority). Negative values require root / `CAP_SYS_NICE`. Existing process: `renice` (separate command). Niceness biases the Linux CFS scheduler but does NOT cap CPU absolutely — under load it allocates a smaller share of CPU.
nice -n 10 ./long-running-job.shSame external GNU `nice`. macOS BSD `nice` differs in flag syntax — accepts `nice -10 cmd` (no `-n`) for niceness 10. For portability across Linux + macOS, use `nice -n 10 cmd` (works on both); avoid the bare-numeric form (Linux nice rejects it).
nice -n 10 ./long-running-job.shSame external. Useful pattern: `nice -n 19 ionice -c 3 ./backup.sh` to combine low CPU priority (`nice 19`) with idle-only IO (`ionice -c 3`) for backups / sync jobs that shouldn't interfere with interactive work.
Start-Process -FilePath .\long-running-job.exe -Priority BelowNormal`Start-Process -Priority` accepts `Idle` / `BelowNormal` / `Normal` / `AboveNormal` / `High` / `RealTime` — a 6-level Windows priority class rather than Linux's 40-step niceness. Mapping: `Idle ≈ nice 19`, `BelowNormal ≈ nice 10`, `Normal ≈ nice 0`, `AboveNormal ≈ nice -5`, `High ≈ nice -10`, `RealTime ≈ nice -20` (avoid `RealTime` — can starve the OS). For an existing process, use `(Get-Process X).PriorityClass = "BelowNormal"`.
start /low long-running-job.exe`start` flags: `/low` ≈ Idle (4), `/belownormal` (6), `/normal` (8 — default), `/abovenormal` (10), `/high` (13), `/realtime` (24 — admin only). Identical to pwsh `Start-Process -Priority` but with cmd argument syntax. For an existing process, no built-in — shell out: `wmic process where ProcessId=1234 CALL setpriority 16384` (16384 = BelowNormal class).
Worked examples
Run a backup at lowest priority so it doesn't slow down interactive work
nice -n 19 ionice -c 3 rsync -a /home /backupStart-Process robocopy -ArgumentList "C:\Users","D:\Backup","/MIR" -Priority Idlestart /low robocopy C:\Users D:\Backup /MIRRun an admin-only high-priority job (requires root / Administrator)
sudo nice -n -10 ./real-time-encode.shStart-Process .\encode.exe -Priority High -Verb RunAsstart /high encode.exeCheck the current niceness of a running process
ps -o pid,ni,comm -p 1234(Get-Process -Id 1234).PriorityClassGotchas
- Linux niceness is an `int` from `-20` (highest) to `19` (lowest) — 40 levels — while Windows has 6 priority CLASSES. The mapping is approximate: pwsh `BelowNormal` (priority class 16384) is roughly Linux `nice 10`, but the actual scheduling behavior differs because Windows uses preemptive priority scheduling with dynamic boosts (active-window foreground gets a 2-tick boost) while Linux CFS uses weighted fair-share. Don't expect identical behavior under heavy load.
- Negative niceness requires `CAP_SYS_NICE` (root on most distros). `nice -n -5 ./X` as a normal user produces a warning + falls back to niceness 0 — the command STILL runs, but at default priority. Always check `ps -o ni -p $$` after launch if you needed high priority.
- On macOS, niceness changes are honored but the BSD scheduler weights them differently than Linux CFS — a `nice 10` task gets significantly less CPU under contention than its Linux equivalent. Cross-platform benchmarks comparing CPU shares with niceness should NOT extrapolate Linux numbers to macOS.
- Windows `RealTime` priority (start `/realtime`, pwsh `-Priority RealTime`) puts the process above OS services — including the mouse cursor, sound drivers, and the security subsystem. Used by RTOS-style apps but trivially crashes interactive sessions. Reserve for kiosk / kiosk-mode workloads with explicit watchdog. Default to `High` if you think you need RealTime.
- pwsh `(Get-Process X).PriorityClass = "High"` requires the calling pwsh session to have at least the same priority class — a `Normal`-priority pwsh CAN set a target process to `High`, but cannot escalate to `RealTime` without elevation. WMI / CIM paths (`Set-CimInstance -InputObject (Get-CimInstance Win32_Process -Filter "ProcessId=1234") -Property @{Priority=128}`) have the same constraints.