Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Niceness and priority processes on Linux system

Tags:

I am looking for a way to modify a process' priority through command line. I found the builtin (bash) nice and the command renice which allow to modify the niceness of the process, but not the actual priority which is calculated by the kernel.

Is there a command which allows to set the priority? (Or am I confused between niceness and priority?)

like image 799
Hugo Avatar asked Apr 19 '11 15:04

Hugo


People also ask

What is process and process priority in Linux?

The process priority determines which process gets more CPU time and which processes can wait for execution at a later, less-demanding time. Linux allows us to set a nice value on a per-user basis, which may differ from the process priority.

How do I find the priority of a process in Linux?

The -l (lowercase L) flag of the ps command displays the nice values and current priority values of the specified processes. The output shows the result of the nice -n 5 command described previously. Process 7568 has an inferior priority of 70.

What is the default niceness level of Linux?

Most system-started processes use the default niceness of 0. If the niceness value is high number like 19 the task will be set to the lowest priority and the CPU will process it whenever it gets a chance. The default nice value is zero.

How do I start a high priority process in Linux?

In Linux, when you start any process or program, it gets the default priority of 0. You can use the ps or top command to display the priority of a running process. You should see the nice value of all processes in the NI column.


1 Answers

The priority of a process in linux is dynamic: The longer it runs, the lower its priority will be. A process runs when its actually using the CPU - most processes on a typical Linux box just wait for I/O and thus do not count as running.

The priority is taken into account when there are more processes running than CPU cores available: Highest priority wins. But as the winning process looses its proirity over time, other processes will take over the CPU at some point.

nice and renice will add/remove some "points" from priority. A process which has a higher nice value will get lesser CPU time. Root can also set a negative nice value - the process gets more CPU time.

Example: There are two processes (1 and 2) calculating the halting problem and one CPU core in the system. Default is nice 0, so both processes get about half of the CPU time each. Now lets renice process 1 to value 10. Result: Process 2 gets a significant higher amount of cpu time as process 1.

Note: In modern desktops there is plenty CPU time available - they are fast these days. Unfortunately HDDs are still relativeley slow on random I/O, so even a nice process can generate enough I/O traffic to significantly slow down a system.

like image 172
Turbo J Avatar answered Sep 22 '22 04:09

Turbo J