LINUX TIPS AND TRICKS --- March 02, 2001

Published by ITworld.com -- changing the way you view IT
http://www.itworld.com/newsletters
________________________________________________________________________________

Know your Scheduler
By Danny Kalev

This week I will present some basic concepts about the Linux scheduler 
and its operation mode.

The scheduler (or dispatcher) is a kernel component responsible for 
coordinating process and thread execution (collectively referred to as 
tasks). The scheduler affects the system's overall performance, perhaps 
more than any other kernel component, by assigning each task a fair 
amount of CPU time based upon the tasks priority and class process. 
However, the scheduler also guarantees the lowest priority tasks aren't 
starved of CPU time.

Linux implements the preemptive multitasking model, whereby the 
scheduler removes a task from the CPU once its allocated time quantum 
has expired. Of course, a task may voluntarily surrender -- technically 
speaking, yield -- its CPU time if it's waiting for another process to 
release a resource. Furthermore, the scheduler reprioritizes tasks. If 
a task has already received some CPU time, then it will have lower 
priority compared to tasks with identical priority that have not. Under 
Linux, a task's priority can range between 20 and -20; the default 
priority is 0, and the highest priority is -20. In other words, the 
lower the value, the higher the priority (a common source of confusion 
for novices). A user can set a priority lower than 0 using the "renice" 
command, but the user must have an administrator's privilege.

Linux supports real time tasks as well. A real-time task always takes 
priority over all non real-time tasks. In essence, a scheduler sets a 
process's state into one of the following modes:

    * Running -- A process is the current system process and is 
      utilizing the system's CPU.
    * Running, ready to run -- The process is in the run queue, waiting 
      for the CPU to become available.
    * Waiting, interruptible -- The process is waiting for a lock or an 
      event. It hasn't disabled incoming signals, so it may be 
      interrupted.
    * Waiting, uninterruptible -- The process is waiting for a lock or 
      an event. It has disabled signals and therefore, it cannot be 
      interrupted.
    * Stopped -- The process has stopped, typically due to a SIGSTOP 
      signal. Such a process may resume execution later (i.e., its 
      state may change to Running) if, for example, it's being executed 
      under the supervision of a debugger. 
    * Zombie -- The process is dying (due to a malfunction or power 
      fault) or has completed its execution. However, its entry hasn't 
      been removed yet from the system's process table.


About the author(s)
-------------------
Danny Kalev is a system analyst and software engineer with more than 10 
years of experience, specializing in C++ and object-oriented analysis 
and design on various platforms including VMS, DOS, Windows, Unix, and 
Linux. His technical interests involve code optimization, networking, 
and distributed computing. He is also a member of the ANSI C++ 
standardization committee and the author of ANSI/ISO C++ Professional 
Programmer's Handbook (Que, 1999). Contact him at linuxnl@excite.com.
________________________________________________________________________________

ADDITIONAL RESOURCES

Scheduling in the user threads library 
Understanding the priority scheme and queue management of user-level 
threads

http://www.unixinsider.com/jsw/lintps_nl/swol-09-2000/
swol-0901-insidesolaris.html

The lightweight process pool 
Maintaining a pool of execution resources for unbound user threads

http://www.unixinsider.com/jsw/lintps_nl/swol-11-2000/
swol-1110-insidesolaris.html

Domo arigato OpalisRobot for intelligent, flexible network assistance

http://www.itworld.com/jump/lintps_nl/www.itworld.com/
Net/3573/IW001220tcrobot/

Priorities revisited 
Jim addresses a consistent thread of questions that have come in over 
the last several months: kernel thread priorities and how they're 
altered by user-level interfaces

http://www.unixinsider.com/jsw/lintps_nl/swol-06-1999/
swol-06-insidesolaris.html

The story of the Linux kernel 
Linus Torvalds explains what makes the Linux kernel great

http://www.linuxworld.com/jlw/lintps_nl/lw-1999-03/
lw-03-opensources.html
________________________________________________________________________________

COMMUNITY DISCUSSIONS

Linux Software Development
Hone your Linux development skills, share your expertise, and put out 
the occasional call for help in this discussion for programmers of all 
levels. Moderated by Danny Kalev.

http://www.itworld.com/jump/lintps_nl/forums.itworld.com/
webx?14@@.ee6b652/256!skip=193

Ask the Geek
Got a question about Linux setup, tuning, security, or maintenance? 
Hackers, newbies, and all the geeks in between knock heads and devise 
solutions in this discussion moderated by LinuxWorld.com's resident 
geek.

http://www.itworld.com/jump/lintps_nl/forums.itworld.com/
webx?14@@.ee6c981/363!skip=315
________________________________________________________________________________

CONTACTS

* For editorial comments, write Andrew Santosusso, Associate Editor, 
  Newsletters at: andrew_santosusso@itworld.com

* For advertising information, write Dan Chupka, Account Executive at:
  dan_chupka@itworld.com

* For recruitment advertising information, write Jamie Swartz, Eastern
  Regional Sales Manager at: jamie_swartz@itworld.com or Paul Duthie,
  Western Regional Sales Manager at: paul_duthie@itworld.com

* For all other inquiries, write Jodie Naze, Product Manager, 
  Newsletters at: jodie_naze@itworld.com
________________________________________________________________________________

PRIVACY POLICY

http://www2.itworld.com/CDA/ITW_Privacy_Policy

Copyright 2001 ITworld.com, Inc., All Rights Reserved.
http://www.itworld.com
