nice command in Linux is used to launch a program with a modified scheduling priority. It allows you to adjust the CPU priority of a process, determining how much system resources it can utilize.
Here’s an overview of how to use the
The basic syntax of the
nice command is as follows:
nice [options] [command [arguments...]]
Here’s how you can use the
- Launching a command with adjusted priority:
To launch a command with a modified priority, you can prepend the
nicecommand to the command you want to execute. For example:
nice -n <priority> command [arguments...]
<priority> with a value ranging from -20 (highest priority) to 19 (lowest priority). The default priority is 0. The lower the value, the higher the priority.
For example, to launch the
myprogram command with a lower priority (higher niceness value), you would run:
nice -n 10 myprogram
myprogram will run with a lower priority, allowing other processes to have higher access to system resources.
- Viewing the current niceness value:
To view the current niceness value of a running process, you can use the
nicecommand followed by the process ID (PID) using the
-noption. For example:
nice -n PID
PID with the actual process ID you want to check.
This will display the current niceness value of the specified process.
- Renicing a running process:
If you want to adjust the priority of a running process, you can use the
renicecommand allows you to change the priority of an already running process by specifying its process ID (PID). Here’s the syntax:
renice <priority> -p PID
<priority> with the desired priority value, and
PID with the process ID of the process you want to modify.
For example, to increase the priority of a process with PID 1234, you would run:
renice -5 -p 1234
This command will lower the niceness value (increase the priority) of the specified process.
Please note that adjusting process priorities with
renice generally requires administrative privileges (root/superuser). Also, please use caution when modifying process priorities, as setting a high priority for a process can potentially impact system performance.
For more information and additional options related to the
renice commands, you can refer to their manual pages by running
man nice and
man renice in the terminal.