Q. How do I run a process with modified scheduling priority under Linux? I’d like to change the priority in the kernel’s scheduler while starting a command.

A. Use nice command to run a program with modified scheduling priority / nicenesses. Nicenesses range at least from -20 (resulting in the most favorable scheduling) through 19 (the least favorable). The default behavior is to increase the niceness by 10.

A niceness should not be confused with a scheduling priority, which lets applications determine the order in which threads are scheduled to run. Unlike a priority, a niceness is merely advice to the scheduler, which the scheduler is free to ignore.

nice syntax (/bin/nice command)

/bin/nice -n NUM

Add integer NUM (-20 to 19) to the niceness.

WARNING! There are multiple versions of the nice command. One built in to the shell, and one in /bin/nice. The syntax may be diffrent on your system. Refer your shell and /bin/nice command man page for details.

Change niceness by 3

Type the command as follows:
$ /bin/nice -n 3 command-name

Only a privileged user may run a process with lower niceness:
$ /bin/nice -n -1 command-name

Shell in build nice command syntax

If you use the csh or tcsh or bash, the syntax is as follows:
nice +n command
I recommend using /bin/nice syntax to avoid confusion and to save time.


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 12 comments so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
12 comments… add one
  • Sekhar Nov 10, 2009 @ 9:44

    Can you specify one example fo nice command to run in redhat

  • rinshad Jan 21, 2011 @ 11:17

    nice is really nice !!

    • wow Feb 14, 2011 @ 2:41

      what a douche comment.

      • DaVince Oct 24, 2014 @ 17:50

        No, your comment is douche. Rinshad’s is just silly.

        • Tweeks Oct 28, 2014 @ 17:30

          Seriously guys.. I’ve never had nice do much for my system scheduler/load wise. ionice seems to have a bit more impact for the ioscheduler.. but have you all ever really seen that much of an improvement on CPU bound processes and using nice on Linux?

          Tweeks

  • anon Jun 6, 2011 @ 16:51

    There’s also the renice command (from bsdutils on Debian-like distros), which is potentially less confusing.

  • nn May 4, 2012 @ 9:27

    Plz give clear explanation of nice command along with example

  • Vinay Kudithipudi May 17, 2012 @ 14:08

    A good example for using nice would be to use it when taring up a huge directory. If you think that is going to impact your IO and other applications running on the server, you can use nice as such

    nice -n 3 tar -cvf test.tar test_dir/*

  • Thomas Weeks Apr 29, 2013 @ 21:31

    Does nice actually work? I’ve never seen much of a scheduling/priority/load change from nicing CPU hungry tasks. I have, however, heard good things about ionice for tweaking io-heavy apps. Maybe you should both nice and ionice a process that is going to hammer the CPU and IO.

    Tweeks

  • Mike Jul 11, 2013 @ 18:11

    So these are both valid?

    nice -20 yum update
    nice -n -20 yum update

  • Tyler Oct 22, 2015 @ 17:08

    If you look at the docs, I think the first is a built-in and the second is the system one

  • Wellington Torrejais da Silva May 29, 2017 @ 17:39

    Thanks!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum