Difference between revisions of "Process Niceness"
m |
|||
Line 5: | Line 5: | ||
renice - change process priority real time. | 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 | ||
+ | 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 === | === 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. | This will list the process ID, the nice level, and the actual command. | ||
ps ax -o pid,ni,cmd | ps ax -o pid,ni,cmd | ||
Line 15: | Line 25: | ||
sudo apt install htop | 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. | ||
+ | |||
+ | |||
+ | 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. | ||
Revision as of 19:45, 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
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.
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.