The 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 nice command:
The basic syntax of the nice command is as follows:
nice [options] [command [arguments...]]
Here’s how you can use the nice command:
- Launching a command with adjusted priority:
To launch a command with a modified priority, you can prepend thenicecommand to the command you want to execute. For example:
nice -n <priority> command [arguments...]
Replace <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
The command 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 thenicecommand followed by the process ID (PID) using the-noption. For example:
nice -n PID
Replace 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 therenicecommand. Therenicecommand 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
Replace <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 nice and 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 nice and renice commands, you can refer to their manual pages by running man nice and man renice in the terminal.