Difference between revisions of "Process Niceness"
m |
m |
||
Line 35: | Line 35: | ||
*Normal users can only run a command or program with low priority. | *Normal users can only run a command or program with low priority. | ||
+ | Example 1: As a non-privileged user we shall launch Discord client at the least important priority (the nicest) | ||
+ | nice -n20 /usr/share/discord/Discord | ||
+ | Now about everything else will have priority to the CPU than does Discord. | ||
you can use the ionice command to start the process with low io priority: | you can use the ionice command to start the process with low io priority: |
Revision as of 19:51, 27 May 2020
NICE and RENICE
nice - set process scheduling priority
renice - change process priority real time.
A kernel scheduler is a unit of the kernel that determines the most suitable process out of all runnable processes to execute next.
There are a total of 140 priorities and two distinct priority ranges implemented in Linux. The first one is a nice value (niceness) which ranges from -20 (highest priority value) to 19 (lowest priority value) and the default is 0.
- niceness of -20 gives the process the most priority
- niceness of 19 gives the process the least priority
Lowest level of niceness (lower means more favorable) you can define is determined by limits.conf
Total number of priorities = 140 Real time priority range(PR or PRI): 0 to 99 User space priority range: 100 to 139
check nice level setting
One way
ps -eo pid,ppid,ni,comm
This will list the process ID, the nice level, and the actual command.
ps ax -o pid,ni,cmd
Using the htop command will show nice level. This requires installation. For Ubuntu/Mint:
sudo apt install htop
changing the program priority
nice runs commands at increased priority, renice can raise or lower but works for processes that are already running.
- If no value is provided, nice sets a priority of 10 by default.
- A command or program run without nice defaults to a priority of zero.
- Only root can run a command or program with increased or high priority.
- Normal users can only run a command or program with low priority.
Example 1: As a non-privileged user we shall launch Discord client at the least important priority (the nicest)
nice -n20 /usr/share/discord/Discord
Now about everything else will have priority to the CPU than does Discord.
you can use the ionice command to start the process with low io priority:
nice -n18 ionice -c3 /path/to/mydaemon
How to renice all threads (and children) of one process
The kernel only handles "runnable entities", that is, something which can be run and scheduled. A thread, is just a kind of process that shares (at least) memory space and signal handlers with another one.