Skip to content
shellmap

niceRun a command at a lower or higher priority in bash, zsh, fish, PowerShell, and cmd across all 5 shells

Equivalents in every shell

Bashunix
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.

Zshunix
nice -n 10 ./long-running-job.sh

Same 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).

Fishunix
nice -n 10 ./long-running-job.sh

Same 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.

PowerShellwindows
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"`.

cmd.exewindows
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

Bash
nice -n 19 ionice -c 3 rsync -a /home /backup
PowerShell
Start-Process robocopy -ArgumentList "C:\Users","D:\Backup","/MIR" -Priority Idle
cmd.exe
start /low robocopy C:\Users D:\Backup /MIR

Run an admin-only high-priority job (requires root / Administrator)

Bash
sudo nice -n -10 ./real-time-encode.sh
PowerShell
Start-Process .\encode.exe -Priority High -Verb RunAs
cmd.exe
start /high encode.exe

Check the current niceness of a running process

Bash
ps -o pid,ni,comm -p 1234
PowerShell
(Get-Process -Id 1234).PriorityClass

Gotchas

  • 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.

WSL & PowerShell Core notes

pwshpwsh on Linux/macOS does NOT carry the `Start-Process -Priority` parameter for Linux niceness — you must shell out to `nice` / `renice` (the Linux pwsh respects `nice -n 10 pwsh ./Run.ps1` from a parent shell, just doesn't set it inline). For cross-OS scripts: `if ($IsLinux -or $IsMacOS) { & nice -n 10 ./job.sh } else { Start-Process ./job.exe -Priority BelowNormal }`.
WSLWSL bash `nice -n 19 cmd` works inside Linux for Linux processes. To launch a Windows process at low priority FROM WSL: `cmd.exe /c start /low notepad.exe` — the `start` builtin runs in the Windows side and honors its own `/low` flag. The Linux side's nice has NO effect on Windows-side processes.

Common tasks using nice

Related commands