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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • 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. setserial: command not found
  2. How to delete unused kernels and keep only the running kernel in CentOS/RHEL
  3. grub2-install: command not found
  4. CentOS / RHEL : How to setup session idle timeout (inactivity timeout) for ssh auto logout
  5. gem: Interact with the package manager for the Ruby programming language
  6. git hash-object: Computes the unique hash key of content and optionally creates an object with specified type
  7. ar – Create, modify, and extract from archives (.a, .so, .o)
  8. nmcli connection Command Examples in Linux
  9. emulator: Manager Android emulators from the command-line
  10. How to uninstall neovim from Ubuntu

You May Also Like

Primary Sidebar

Recent Posts

  • glab Command Examples
  • “glab repo” Command Examples
  • “glab release” Command Examples
  • “glab pipeline” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright