Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

nice

Start a command with a changed CPU priority (nice value from -20 to 19).

Level
RHCSA exam
Group
Processes and jobs
Needs root
For changes
Package
coreutils

What it does

The nice value decides how much CPU a process gets when the CPU is busy: -20 = highest priority, 19 = lowest, 0 = normal. nice -n 10 CMD starts CMD nicer than normal. Without -n, nice adds 10.

Normal users may only make processes nicer (higher numbers). Negative values need root. To change a running process use renice.

How to write it

nice [-n ADJUSTMENT] [COMMAND [ARGUMENT]...]

Options 3

Most used

-n, --adjustment=N
Add N to the nice value (default 10).
--help
Show help.
--version
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Run a backup with low priority

    nice -n 19 tar -czf /tmp/home.tgz /home

    Users and services keep their speed.

  2. 2Default adjustment

    nice sleep 100 &
    ps -o ni,cmd -p $!
     NI CMD
     10 sleep 100

    Without -n: +10.

  3. 3Higher priority (root)

    nice -n -5 /usr/local/bin/important-job

    Only root may use negative values.

  4. 4Normal user tries a negative value

    nice -n -5 sleep 1
    nice: cannot set niceness: Permission denied

    The command still runs, with nice 0.

  5. 5Show the current nice value

    nice
    0

    Without a command: print your niceness.

  6. 6Low CPU and low disk priority together

    nice -n 19 ionice -c3 rsync -a /data/ /backup/data/

    ionice -c3 = only use the disk when nobody else does.

  7. 7Compile without slowing the system

    nice -n 15 make -j"$(nproc)"

    Use all cores, but give way to others.

  8. 8Check the NI column in top

    top

    Column NI shows the nice value; PR the kernel priority.

  9. 9Set the nice value of a service

    systemctl edit myapp

    Add [Service] and Nice=10 — services are not started with nice.

  10. 10Run a cron job nicely

    crontab -l | grep nice
    0 2 * * * nice -n 19 /usr/local/bin/report.sh

    Reports at night with low priority.

Watch out

  • Nice only matters when the CPU is busy. On an idle CPU every process gets what it wants.

Exit codes

0The exit status of the command.
125nice itself failed.
126The command could not be run.
127The command was not found.