• 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

UNIX / Linux : How to change the niceness (priority) of a process

by admin

What is process priority (niceness)

All process when spawned, they are assigned a priority based on a numeric value called as “nice value“. The priority of a process denotes how much processor time allocated to that process. There are 40 niceness values, with –20 being the highest and +19 the lowest. Most system-started processes use the default niceness of 0. If the niceness value is high number like 19 the task will be set to the lowest priority and the CPU will process it whenever it gets a chance. The default nice value is zero. A child process inherits the niceness of its calling process in calculating its priority.

Viewing the niceness of the process

You can view the niceness of the process using the command ps, top etc. To view the default niceness value use the below command:

# nice
0

To check the niceness of the currently running process :

# ps -elf

At this point you are probably wondering how you can set your own priority levels on processes. To change the priority when issuing a new command you do

# nice -n [nice value] [command]

For example to run the yum update command with nice value of +10 which gives it less priority over other processes. This makes sure that yum update does not load the system more.

# nice -n 10 yum update

Setting Priority of currently running process

To change the priority of an existing process use the renice command :

# renice [nice value] -p [process id]

For Example to change the priority of the currently running process (with pid 390) to 15.

# renice 15 -p 390
390: old priority 0, new priority 15
Note: Only root can apply negative nice values.

Setting default niceness for a particular process

Sometimes it is helpful to give specific users lower priority than others to keep system resources allocated in the proper places like core services and other programs. You can set the default nice value of a particular user or group in the /etc/security/limits.conf file.

– For users, it uses this syntax:

# vi /etc/security/limits.conf
[username] [hard|soft] priority [nice value]

– For groups, it uses this syntax:

# vi /etc/security/limits.conf
[@groupname] [hard|soft] priority [nice value]

For example, you can have below entries for user and group respectively.

# vi /etc/security/limits.conf
user01 hard priority -10
@group01 hard priority -10

This would add priority to all the applications running under user ‘user01’ or group ‘group01’ priority set to ‘-10’

Filed Under: Linux

Some more articles you might also be interested in …

  1. apt-mark Command Examples in Linux
  2. LVM and multipathing – sample LVM filter strings
  3. Unable to Start RDMA Services on CentOS/RHEL 7
  4. DNS configuration file /etc/named.rfc1912.zones explained
  5. Examples of using dmsetup command in Linux
  6. numlockx: command not found
  7. jasmine-node: command not found
  8. gnome-calculator: command not found
  9. Understanding TCP Wrappers (/etc/hosts.allow & /etc/hosts.deny) in Linux
  10. xz: command not found

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