226 lines
8.7 KiB
HTML
226 lines
8.7 KiB
HTML
<HTML>
|
|
<HEAD>
|
|
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
|
<META NAME="Generator" CONTENT="Microsoft Word 97">
|
|
<META NAME="Template" CONTENT="C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\html.dot">
|
|
<META NAME="GENERATOR" CONTENT="Mozilla/4.01b6C [en] (X11; I; Linux 2.1.47 i486) [Netscape]">
|
|
<TITLE>Processes and Process Context</TITLE>
|
|
</HEAD>
|
|
<BODY BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#800080">
|
|
<FONT COLOR="#3366FF"><FONT SIZE=+3>Scheduling</FONT></FONT>
|
|
|
|
<P><FONT SIZE=+1>A scheduler is responsible for the coordination of the
|
|
running of processes to manage their access to the system resources such
|
|
that each candidate process gets a fair share of the available process
|
|
time, with the utilisation of the CPU being maximised. The scheduler (dispatcher)
|
|
must ensure that processes gain access to the CPU for a time relative to
|
|
its designated priority and process class and that no process is starved
|
|
of access to the CPU, no matter if it is the lowest priority task available.</FONT>
|
|
|
|
<P><FONT SIZE=+1> A process may choose to voluntarily give up it's
|
|
use of the microprocessor when it must wait, usually for some system resource
|
|
or for synchronisation with another process. Alternatively the scheduler
|
|
may pre-emptively remove the thread or process from the CPU at the expiry
|
|
of it's allocated time quantum. The scheduler chooses which is the most
|
|
appropriate process to run next.</FONT>
|
|
|
|
<P><FONT SIZE=+1> Scheduling is an operation of the kernel, which
|
|
defines the following process states :</FONT>
|
|
|
|
<P><FONT SIZE=+1> </FONT>
|
|
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=7 WIDTH="491" >
|
|
<TR>
|
|
<TD VALIGN=TOP WIDTH="48%"><B><FONT COLOR="#FF0000"><FONT SIZE=+1>Linux</FONT></FONT></B></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="4%"><FONT SIZE=+1> </FONT></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="48%"><B><FONT COLOR="#FF0000"><FONT SIZE=+1>Windows
|
|
NT</FONT></FONT></B></TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD VALIGN=TOP WIDTH="48%"><FONT SIZE=+1><FONT COLOR="#00FF00">Running
|
|
:</FONT> The process is the current system process and is on the CPU carrying
|
|
out it's execution. </FONT></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="4%"><FONT SIZE=+1> </FONT></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="48%"><FONT SIZE=+1><FONT COLOR="#00FF00">Running
|
|
: </FONT>The process (thread) is the currently active process on the CPU.</FONT></TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD VALIGN=TOP WIDTH="48%"><FONT SIZE=+1><FONT COLOR="#00FF00">Running
|
|
: </FONT><FONT COLOR="#009900">Ready to Run :</FONT> The process is in
|
|
a run queue ready to use the CPU when available.</FONT></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="4%"><FONT SIZE=+1> </FONT></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="48%"><FONT SIZE=+1><FONT COLOR="#00FF00">Standby
|
|
: </FONT>The thread has been selected to run next by the processor, only
|
|
one thread can be in this state.</FONT></TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD VALIGN=TOP WIDTH="48%"><FONT SIZE=+1><FONT COLOR="#00FF00">Waiting
|
|
: </FONT><FONT COLOR="#008080">interruptable</FONT><FONT COLOR="#FFFF00">
|
|
:</FONT><FONT COLOR="#00FF00"> </FONT>The process is waiting for a resource
|
|
or event but signals are not blocked and it may be interrupted.</FONT></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="4%"><FONT SIZE=+1> </FONT></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="48%"><FONT SIZE=+1><FONT COLOR="#00FF00">Ready :
|
|
</FONT>The thread is simply waiting to execute and is a candidate for selection
|
|
by the scheduler for entering standby at the next scheduling cycle<FONT COLOR="#00FF00">.</FONT></FONT></TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD VALIGN=TOP WIDTH="48%"><FONT SIZE=+1><FONT COLOR="#00FF00">Waiting
|
|
: </FONT><FONT COLOR="#008080">uninterruptable</FONT><FONT COLOR="#FFFF00">
|
|
:</FONT> The process is waiting for a resource or event but has disable
|
|
signals such that it cannot be interrupted.</FONT></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="4%"><FONT SIZE=+1> </FONT></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="48%"><FONT SIZE=+1><FONT COLOR="#00FF00">Waiting
|
|
:</FONT> The thread is waiting for synchronisation events, it has been
|
|
directed to suspend by the environment subsystem or is waiting on I/O.</FONT></TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD VALIGN=TOP WIDTH="48%"><FONT SIZE=+1><FONT COLOR="#00FF00">Stopped
|
|
:</FONT> The process has been stopped, usually by a SIGSTOP signal such
|
|
as when performing debugging.</FONT>
|
|
|
|
<P><FONT SIZE=+1> </FONT></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="4%"><FONT SIZE=+1> </FONT></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="48%"><FONT SIZE=+1><FONT COLOR="#00FF00">Transition
|
|
:</FONT> The thread is ready to execute but the resources it needs are
|
|
not available. (e.g. the thread's kernel stack is paged out of memory).</FONT></TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD VALIGN=TOP WIDTH="48%"><FONT SIZE=+1><FONT COLOR="#00FF00">Zombie :</FONT>
|
|
The process has completed and is ready to die, the scheduler has not yet
|
|
detected this so it?s task_struct structure is still present.</FONT></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="4%"><FONT SIZE=+1> </FONT></TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="48%"><FONT SIZE=+1><FONT COLOR="#00FF00">Terminated
|
|
:</FONT> The thread has finished executing and the object manager decides
|
|
whether the thread is deleted. If the executive has a pointer to the thread
|
|
it may be reinitialised and reused. </FONT></TD>
|
|
</TR>
|
|
</TABLE>
|
|
<FONT SIZE=+1> </FONT>
|
|
|
|
<P><FONT SIZE=+1>The scheduling of tasks on the different operating systems
|
|
is similar, but each OS solves the problem in it's own way :</FONT>
|
|
|
|
<P><FONT SIZE=+1> </FONT>
|
|
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=7 WIDTH="490" >
|
|
<TR>
|
|
<TD VALIGN=TOP WIDTH="48%">
|
|
<UL><B><FONT COLOR="#FF0000"><FONT SIZE=+1>Linux</FONT></FONT></B></UL>
|
|
</TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="4%">
|
|
<UL><FONT SIZE=+1> </FONT></UL>
|
|
</TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="48%">
|
|
<UL><B><FONT COLOR="#FF0000"><FONT SIZE=+1>Windows NT</FONT></FONT></B></UL>
|
|
</TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD VALIGN=TOP WIDTH="48%">
|
|
<UL><FONT SIZE=+1>Tasks have a priority which ranges from a setting of
|
|
-20 to +20. The default priority of a task is 0 with -20 being the highest.
|
|
Only the administrator can reset a process's priority to be less than 0,
|
|
but normal users can adjust priorities in the positive range. This is done
|
|
using the 'renice' command, though internally Linux uses a time quantum
|
|
counter (in 'jiffies') to record this in the task_struct.</FONT>
|
|
|
|
<P><FONT SIZE=+1>New processes inherit the priority of their parent.</FONT></UL>
|
|
</TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="4%">
|
|
<UL><FONT SIZE=+1> </FONT></UL>
|
|
</TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="48%">
|
|
<UL><FONT SIZE=+1>Threads have a priority which ranges from 1 to 31 with
|
|
8 being the user default and 31 being the highest. Priority 0 is reserved
|
|
for system use. Only the administrator can set a processes priority to
|
|
be above 15, normal users can set a process's priority in the 1 to 15 range
|
|
in a two step process by first setting the process class and then setting
|
|
the relative priority within the class. This is done using the Task Manager.</FONT>
|
|
|
|
<P><FONT SIZE=+1>New processes inherit the priority of their creating process.</FONT></UL>
|
|
</TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD VALIGN=TOP WIDTH="48%">
|
|
<UL><FONT SIZE=+1> Real time processes are supported. Any real time
|
|
process will have higher priority than all non real-time processes. </FONT>
|
|
|
|
<P><FONT SIZE=+1> </FONT>
|
|
|
|
<P><FONT SIZE=+1> </FONT></UL>
|
|
</TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="4%">
|
|
<UL><FONT SIZE=+1> </FONT></UL>
|
|
</TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="48%">
|
|
<UL><FONT SIZE=+1>Processes having priorities between 16 and 31 are real-time
|
|
processes which are members of the realtime class.</FONT>
|
|
|
|
<P><FONT SIZE=+1> <I>time-critical</I> and <I>idle</I> modifiers may
|
|
move a dynamic thread's priority to the top or bottom of it's dynamic range
|
|
respectively.</FONT></UL>
|
|
</TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD VALIGN=TOP WIDTH="48%">
|
|
<UL><FONT SIZE=+1>Threads that have already received some CPU time will
|
|
have lower priority than other of the same priority which have not.</FONT></UL>
|
|
</TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="4%">
|
|
<UL><FONT SIZE=+1> </FONT></UL>
|
|
</TD>
|
|
|
|
<TD VALIGN=TOP WIDTH="48%">
|
|
<UL><FONT SIZE=+1>Non real-time threads may be boosted in priority should
|
|
(e.g.) a blocked thread receive an event if was waiting for. This boost
|
|
decays over time as the thread receives CPU time.</FONT></UL>
|
|
</TD>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<UL><FONT SIZE=+1> The following diagram shows the state machine used
|
|
for the Windows NT scheduler. From the above tables it can be seen that
|
|
although the corresponding state for machine for Linux will be different
|
|
it will be similar. Linux also has kernel mechanisms called <I>bottom half
|
|
handlers</I> which are not covered here.</FONT></UL>
|
|
<FONT SIZE=+1> </FONT>
|
|
<DIR>
|
|
<DIR><IMG SRC="../gx/flower/schedule.gif" HEIGHT=350 WIDTH=400>
|
|
<BR>
|
|
<BR>
|
|
<BR>
|
|
<DIV ALIGN=right><A HREF="threads.html"><IMG SRC="../gx/flower/cyan_lef.gif" BORDER=0 HEIGHT=31 WIDTH=31></A><A HREF="page1.html"><IMG SRC="../gx/flower/cyan_up.gif" BORDER=0 HEIGHT=31 WIDTH=31></A><A HREF="mutex.html"><IMG SRC="../gx/flower/cyan_rig.gif" BORDER=0 HEIGHT=31 WIDTH=31></A></DIV>
|
|
|
|
<BR> </DIR>
|
|
</DIR>
|
|
|
|
</BODY>
|
|
</HTML>
|