Nice and Renice Command in Linux with Examples
Last Updated :
06 Sep, 2024
In Linux, managing process priority is crucial for optimizing system performance, especially in environments where multiple processes compete for CPU resources. The nice and renice commands allow users to adjust the scheduling priority of processes, influencing how the Linux kernel allocates CPU time among them.
- 'nice' Command: This command is used to start a new process with a specific priority, known as the "nice value." A higher nice value lowers the process's priority, while a lower (negative) nice value increases it. Processes with higher priority receive more CPU time.
- 'renice' Command: Unlike nice, which sets the priority when starting a process, renice modifies the priority of an already running process. This flexibility allows system administrators to manage process priorities based on the current system load dynamically.
Working with 'nice' and 'renice' Command
Here are some practical ways to use 'nice' and 'renice' commands to manage process priorities effectively:
1. To check the nice value of a process.
To check the current nice value of a specific process, you can use the 'ps' command combined with 'grep':
ps -el | grep terminal

The eight highlighted value is the nice value of the process.
2. To set the priority of a process
To start a new process with a specific nice value, use the nice command:
nice -10 gnome-terminal

This sets the nice value of the gnome-terminal process to '10', lowering its priority compared to processes with a nice value closer to '0' or negative values.
3. To set the negative priority for a process
To give a process higher priority by assigning a negative nice value, use:
nice --10 gnome-terminal

Negative nice values increase the process's priority, allowing it to receive more CPU time. This is especially useful for critical tasks that need to run faster.
4. Changing priority of the running process.
To modify the priority of an already running process, use the 'renice' command with the process ID (PID):
sudo renice -n 15 -p 77982

This will change the priority of the process with pid 77982.
5. To change the priority of all programs of a specific group.
You can also adjust the priority of all processes within a specific group by specifying the group ID (GID):
renice -n 10 -g 4

This command will set all the processes of gid 4 priority to 10, reducing their CPU time allocation.
6. To change the priority of all programs of a specific user.
To change the priority of all processes belonging to a specific user, use the renice command with the user ID (UID):
sudo renice -n 10 -u 2

This will set all the processes of user 2 to 10, making them lower priority.
Conclusion
The 'nice' and 'renice' commands in Linux provide powerful tools for managing process scheduling priorities, allowing system administrators and users to control how CPU resources are allocated among running processes. By understanding and using these commands effectively, you can optimize system performance, ensure critical applications receive the necessary resources, and maintain a balanced workload on your Linux system.
Similar Reads
reset command in Linux with Examples
reset command in the Linux system is used to initialize the terminal. This is useful once a program dies leaving a terminal in an abnormal state. Note that you may have to type reset to get the terminal up and work, as carriage-return may no longer work in the abnormal state. Also, the terminal will
3 min read
nproc Command in Linux with Examples
nproc It is a simple Unix command which is used to print the number of processing units available in the system or to the current process. This command could be used in system diagnostics and related purposes. It is part of GNU Core utils, so it comes pre-installed with all modern Linux operating sy
3 min read
whereis command in Linux with Examples
'whereis' command is used to find the location of source/binary file of a command and manuals sections for a specified file in Linux system. If we compare 'whereis' command with 'find' command they will appear similar to each other as both can be used for the same purposes but 'whereis' command prod
4 min read
Sed Command in Linux/Unix With Examples
The SED command is one of the most powerful commands used during the process of text processing in Linux/Unix operating systems. The SED command is typically invoked for executing operations such as replace and search, text manipulation, and stream editing.With SED, you can manipulate text files wit
9 min read
rev command in Linux with Examples
rev command in Linux is used to reverse the lines characterwise. This utility reverses the order of the characters in each line by copying the specified files to the standard output. If no files are specified, then the standard input will be read. Here, we will explore the syntax, examples, and opti
3 min read
rcp Command in Linux with examples
When working in a Linux environment, there often comes a time when you need to transfer files from one computer to another. While more secure options like scp or rsync exist, the rcp (Remote Copy Protocol) command offers a simple and efficient way to copy files between systems, especially for beginn
5 min read
ranlib command in Linux with Examples
ranlib command in Linux is used to generate index to archive. ranlib generates an index to the contents of an archive and it will be stored in the archive. The index lists each symbol defined by a member of an archive which is simply a relocatable object file. You may use 'nm -s' or 'nm âprint-armap
4 min read
username Command in Linux With Examples
Linux as an operating system holds the capabilities of handling multiple users each with a username and a display name (Full Name). So it is important to keep a check on the users and their related information in order to maintain the integrity and security of the system. Whenever a user is added it
4 min read
ar command in Linux with examples
The 'ar' command in Linux is a versatile tool used for creating, modifying, and extracting files from archives. An archive is essentially a collection of files bundled together in a specific structure, making it easy to manage multiple files as a single entity. Each file within the archive is referr
5 min read
tr command in Unix/Linux with examples
The tr command is a UNIX command-line utility for translating or deleting characters. It supports a range of transformations including uppercase to lowercase, squeezing repeating characters, deleting specific characters, and basic find and replace. It can be used with UNIX pipes to support more comp
4 min read