• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

nice Command Examples in Linux

by admin

The nice command enables you to run a command with a different nice value than the default. The -n option increments the nice value by the given integer; if you don’t provide an integer, then the command will assume an increment of 10. By running nice without any options, you’ll see the default nice value. You must have the root user authority to run a command at a higher priority. Once lowered, the priority for any process cannot be increased by normal users, even if they own the process.

Syntax

The syntax of the nice command is:

# nice [-n {nice value increment}] [command]

Normally, when a process is started, it gets the default priority value of 0. The nice command is used to start a process with a different priority. Its syntax is as follows:

# nice -n [NICELEVEL] [command]

Here’s an example of setting a big job to run at nice level 7:

# nice −7 sort VeryLargeFile > outfile

If you run nice without a level, 10 is used. Normal processes (run without nice) run at level zero, which you can see by running nice with no arguments:

# nice
0

The superuser can also lower the nice level, increasing a process’s priority:

# nice --10 myprogram

(Yes, that’s “dash negative 10”.) To see the nice levels of your jobs, use ps and look at the “NI” column:

# ps -o pid,user,args,nice

The top command can also be used to display the priority of processes. It shows two columns, named NI (displaying the nice level mapping of processes) and PR (displaying the priority value mapping in a kernel to a larger priority queue).

Modyfying priority

Assigning a low nice value, that is, a higher priority, to a CPU-hungry process will impact the performance of other processes running on the same Linux system. Hence, only root is allowed to give a higher priority to a process, for example, setting negative nice values on running processes.

Normal users can only lower the priority of their processes, that is, they can set only a higher positive value than the existing nice value for a given process.

Filed Under: Linux

Some more articles you might also be interested in …

  1. SSH Connection Refused by TCP Wrapper
  2. udevadm Command Examples in Linux
  3. How To Identify User Deleting Files From A Given Directory in Linux
  4. Working with Vim editor (Text Editor)
  5. What causes iptables to load every time after a reboot even when it’s completely turned off
  6. nsenter: command not found
  7. ipcs Command Examples in Linux
  8. CentOS / RHEL : How to create a Thinly Provisioned Logical Volume
  9. User Unable To Edit crontab, Error: “/tmp/crontab.Lm34gsJV: Permission denied”
  10. How to start/stop Virtual Machines in RedHat Virtualization

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright