Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

nice

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

Niveau
RHCSA-examen
Groep
Processen en jobs
Root nodig
Voor wijzigingen
Pakket
coreutils

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

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.

Zo schrijf je het

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

Opties 3

Meest gebruikt

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

Voorbeelden 10

$ als gewone gebruiker# als root (of met 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.

Let op

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

Exitcodes

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

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man nice