A Tip A Day [:: ATAD ::]

a fortune, two cents a day

ATAD #21 – Linux process priority range

with 6 comments

The Linux kernel implements two separate priority ranges.

The first is the nice value, a number from –20 to 19 with a default of zero. Larger nice values correspond to a lower priority (you are being nice to the other processes on the system). Processes with a lower nice value (higher priority) run before processes with a higher nice value (lower priority). The nice value also helps determine how long a processor timeslice the process receives. A process with a nice value of –20 receives the maximum timeslice, whereas a process with a nice value of 19 receives the minimum timeslice. Nice values are the standard priority range used in all Unix systems.

The second range is the real-time priority (rtprio). By default, it ranges from zero to 99. All real-time processes are at a higher priority than normal processes. Linux implements real-time priorities in accordance with POSIX.

In order to select a process to run, the Linux scheduler must consider the priority of each process. Actually, there are two kinds of priority:

Static priority
This kind is assigned by the users to real-time processes and ranges from 1 to 99 (highest). It is never changed by the scheduler. The sys_sched_get_priority_max( ) routine returns the static priority of the process, it returns 0 for non-realtime processes.

Dynamic priority
This kind applies only to conventional processes (non realtime processes)

Processes have an initial priority specified as the nice value. This value is stored in the static_prio member of the process’s task_struct. The value is called the static priority because it does not change from what the user specifies. The scheduler, in turn, bases its decisions on the dynamic priority that is stored in prio. The dynamic priority is calculated as a function of the static priority and the task’s interactivity

The static priority of a real-time process is always higher than the dynamic priority of a conventional one: the scheduler will start running conventional processes only when there is no real-time process in a TASK_RUNNING state.

.

Do experiment with the ps command

~$ ps -eo pid,rtprio,ni,pri,comm
PID RTPRIO  NI PRI COMMAND
1      -   0  19 init
2      -  -5  24 kthreadd
3     99   - 139 migration/0
4      -  -5  24 ksoftirqd/0

.

This scale could probably illustrate priorities better

HIGH PRIORITY – – – – – > – – – – – > – – – – – > – – – – – > – – – – LEAST PRIORITY
……..real time priority (static priority)…….| …. nice value (dynamic priority) …..
99 ……………………….. 50 ……………………… 1 | -20 …….. -10 …….. 0 …….. 10 ……. 19

.

Further Reading: Linux Process Scheduler, Linux Process Scheduling

__tipped__
vinaydeep

Advertisement

Written by veed

August 19, 2008 at 7:50 am

6 Responses

Subscribe to comments with RSS.

  1. […] Go to the author’s original blog: ATAD #21 – Linux process priority range […]

  2. […] – bookmarked by 2 members originally found by JENTHELUSH on 2008-08-26 ATAD #21 – Linux process priority range https://atipaday.wordpress.com/2008/08/19/atad-21-linux-process-priority-range/ – bookmarked by 1 […]

    Bookmarks about Process

    September 22, 2008 at 2:45 am

  3. FANTASTIC!

    PrureGake

    April 9, 2009 at 1:31 pm

  4. Hey, cool tips. Perhaps I’ll buy a bottle of beer to that man from that chat who told me to visit your blog 🙂

    Random T.

    April 22, 2009 at 7:01 am

  5. Just to let you know your webpage looks a little bit strange in Firefox on my computer with Linux .

    click

    May 27, 2012 at 7:44 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: