Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents
Up to --> The Kernel

· Processes
· Linux Processes
· Executing Programs
· Process Files
· Identifiers
· The Life Cycle of Processes
· Process Scheduling
· Scheduling in Multiprocessor Systems
· Creating a Process
· Executing Programs
· Processes in Action
· Process Virtual Memory
· Times and Timers

Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
Copyright Info
Terms of Use
Privacy Info
Masthead / Impressum
Your Account

Private Messages

News Archive
Submit News
User Articles
Web Links


The Web

Who's Online
There are currently, 89 guest(s) and 0 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here

Linux Tutorial - The Operating System - The Kernel - Processes - Process Scheduling
  The Life Cycle of Processes ---- Scheduling in Multiprocessor Systems  

Process Scheduling

Like many dialects of UNIX, the process scheduler is a function inside the kernel, not a separate process. Actually, it's better to say that process scheduling is done by two functions working together, both of which are a part of sched.c. The first function is schedule(), which does the actual scheduling. The other is do_timer(), which is called at different times and whose function is to update the times of each process. Essentially, this is used to keep track of how long each process has been running, how long it has had the processors, how long it has been in user mode, how long it has been in kernel mode, etc.

In the section on operating system basics, I mentioned that each process gets a time slice that's 1/100th of a second long. At the end of each time slice, the do_timer() function is called and priorities are recalculated. Each time a system call returns to user mode, do_timer() is also called to update the times.

Scheduling processes is not as easy as finding the process that has been waiting the longest. Some operating systems do this kind of scheduling, which is referred to as "round-robin." The processes could be thought of as sitting in a circle. The scheduling algorithm could then be though of as a pointer that moves around the circle, getting to each process in turn. The Linux scheduler does a modified version of round-robin scheduling, however, so that processes with a higher priority get to run more often and longer.

Linux also allows you to be nice to your fellow processes. If you feel that your work is not as important as someone else's, you might want to consider being nice to them. This is done with the nice command, the syntax of which is

nice <nice_value> <command>

For example, if you wanted to run the date command with a lower priority, you could run it like this:

nice -10 date

This decreases the start priority of the date command by 10. Nice values range from 19 (lowest priority) to -20 (highest priority). Note that only root can increase a process' priority, that is, use a negative nice value. The nice value only affects running processes, but child processes inherit the nice value of their parent. By default, processes that users start have a nice value of 20.

The numeric value calculated for the priority is the opposite of what we normally think of as priority. A better way of thinking about it is like the pull-down number tickets you get at the ice cream store. The lower the number, the sooner you'll be served. So it is for processes as well.

Although the nice command only works when you start a process, you can change the nice value on a running process by using the renice command. It uses the same priorities as nice, but is used on processes that are already running. It can take the -p option for a specific PID, the -g option for a process group, or -u for the processes belonging to a specific user.

The number of times the clock interrupts per second, and therefore the numbers of times the priority is recalculated, is defined by the HZ system variable. This is defined by default to be 100HZ, or 100 times a second. However, we are assuming that the priorities are only calculated once a second instead of 100 times.

 Previous Page
The Life Cycle of Processes
  Back to Top
Table of Contents
Next Page 
Scheduling in Multiprocessor Systems


Test Your Knowledge

User Comments:

You can only add comments if you are logged in.

Copyright 2002-2009 by James Mohr. Licensed under modified GNU Free Documentation License (Portions of this material originally published by Prentice Hall, Pearson Education, Inc). See here for details. All rights reserved.



Security Code
Security Code
Type Security Code

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!

Amazon Wish List

Did You Know?
The Linux Tutorial welcomes your suggestions and ideas.


Tell a Friend About Us

Bookmark and Share

Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.09 Seconds