Sei sulla pagina 1di 153

MASTER OF COMPUTER

APPLICATIONS (MCA)
SEMESTER: III

Prepared By: Miss K.N.Dandhwani


Subject Code
3630003

Subject Name
Basic Computer Science – 2

Prepared By: Miss K.N.Dandhwani


Chapter 1
Computer System Overview

Prepared By: Miss K.N.Dandhwani


Operating System
• Exploits the hardware resources of one or more
processors
• Provides a set of services to system users
• Manages secondary memory and I/O devices
1.1 A Computer’s
Basic Elements
At a top level computer consists of processor,
memory, and I/O components, with one or more
modules of each type.
These components are interconnected in some
fashion to achieve the main function of the
computer, which is to execute programs.
Thus, there are four main structural elements:
– Processor
– Main Memory
– I/O Modules
– System Bus
Processor
• Controls operation, performs data processing and
also exchanges data with memory (with the use of
internal registers)
• Two internal registers
– Memory Address Resister (MAR)
– Memory Buffer Register (MBR)
• I/O address register (I/OAR)
• I/O buffer register (I/OBR)
Main Memory
• Stores data and programs.
• Volatile
– Data is typically lost when power is removed
• Referred to as real memory or primary memory
• Consists of a set of locations defined by
sequentially numbers addresses
– Containing either data or instructions
I/O Modules
• Moves data between the computer and the
external environment such as:
– Storage (e.g. hard drive)
– Communications equipment
– Terminals
• Specified by an I/O Address Register
– (I/O AR)
System Bus
• Provides for communication among processors,
main memory, and I/O modules
Top-Level View
Chapter 2
Operating System Overview

Prepared By: Miss K.N.Dandhwani


2.1 Operating System
• A program that controls the execution of
application programs.
• An interface between applications and
hardware.
• Main objectives of an OS:
– Convenience
– Efficiency
– Ability to evolve
Operating System as a
User/Computer Interface
• The hardware and software used in providing
applications to a user can be viewed in a layered
or hierarchical fashion shown in following figure.
• The user of this applications, end user, is not
concerned with the details of hardware.
• So the end user views a computer system in
terms of a set of applications.
• Applications can be developed by application
programmer using programming languages.
Operating System as a
User/Computer Interface
• If one were to develop an application program
as a set of machine instructions that is
completely responsible for controlling the
computer hardware.
• Some of these programs are referred to as
utilities.
• The most important collection of system
programs comprises the OS.
Services Provided
by the Operating System
• Program development
– Editors and debuggers.
• Program execution
– OS handles scheduling of numerous tasks
required to execute a program
• Access I/O devices
– Each device will have unique interface
– OS presents standard interface to users
Services cont…
• Controlled access to files
– Accessing different media but presenting a
common interface to users
– Provides protection in multi-access systems
• System access
– Controls access to the system and its
resources
Services cont…
• Error detection and response
– Internal and external hardware errors
– Software errors
– Operating system cannot grant request of
application
• Accounting
– Collect usage statistics
– Monitor performance
The Role of an OS
• A computer is a set of resources for the
movement, storage, and processing of
data.
• The OS is responsible for managing these
resources.
Operating System
as Software
• The OS functions in the same way as an
ordinary computer software
– It is a program that is executed by the CPU
• Operating system relinquishes control of
the processor
OS as
Resource Manager
Chapter 3
Process Description and Control

Prepared By: Miss K.N.Dandhwani


Roadmap
– How are processes represented and
controlled by the OS. (3.1)
– Process states which characterize the
behaviour of processes. (3.2)
– Data structures used to manage processes.
(3.3)
– Ways in which the OS uses these data
structures to control process execution. (3.4)
– Discuss process management in UNIX
SVR4.(3.7)
Requirements of an
Operating System
• Fundamental Task: Process Management
• The Operating System must
– Interleave the execution of multiple processes
– Allocate resources to processes, and protect
the resources of each process from other
processes,
– Enable processes to share and exchange
information
– Enable synchronization among processes
Concepts
• From earlier chapters we saw:
– Computer platforms consists of a collection of
hardware resources

– Computer applications are developed to


perform some task

– It is inefficient for applications to be written


directly for a given hardware platform
Concepts cont…
– OS provides an interface for applications to
use

– OS provides a representation of resources


that can be requested and accessed by
application
The OS Manages
Execution of Applications
• Resources are made available to multiple
applications
• The processor is switched among multiple
application
• The processor and I/O devices can be
used efficiently
3.1 What is a “process”?
• A program in execution
• An instance of a program running on a
computer
• The entity that can be assigned to and
executed on a processor
• A unit of activity characterized by the
execution of a sequence of instructions, a
current state, and an associated set of
system instructions
Process Elements
• A process is comprised of:
– Program code (possibly shared)
– A set of data
– A number of attributes describing the state of
the process
Process Elements
• While the process is running it has a
number of elements including
– Identifier
– State
– Priority
– Program counter
– Memory pointers
– Context data
– I/O status information
– Accounting information
Process Elements
• The information in the preceding list is
stored in a data structure, called a Process
Control Block (PCB).
Process Control Block
• Contains the process
elements
• Created and manage by
the operating system
• Allows support for
multiple processes
Roadmap
– How are processes represented and
controlled by the OS. (3.1)
– Process states which characterize the
behaviour of processes. (3.2)
– Data structures used to manage processes.
(3.3)
– Ways in which the OS uses these data
structures to control process execution. (3.4)
– Discuss process management in UNIX
SVR4.(3.7)
3.2 Process States
• A program execution involves a sequence
of instructions within that program.
• The behavior of an individual process is
shown by listing the sequence of
instructions that are executed.
• This list is called a Trace.
• Dispatcher is a small program which
switches the processor from one process
to another.
Process Execution
• Consider three
processes being
executed
• All are in memory
(plus the
dispatcher)
• Lets ignore virtual
memory for this.
Trace from the
processes point of view
• Each process runs to completion
Trace from Processors
point of view

Timeout
I/O
Two-State Process Model
• Process may be in one of two states
– Running
– Not-running
Queuing Diagram

Etc … processes moved by the dispatcher of the OS to the CPU then back
to the queue until the task is competed
Process Birth and Death
Creation Termination
New batch job Normal Completion
Interactive Login Memory unavailable
Created by OS to Protection error
provide a service
Spawned by existing Operator or OS
process Intervention

See tables 3.1 and 3.2 for more


Process Creation
• When a new process is to be added to
those currently being managed, the OS
builds a data structure to manage the
process
• Traditionally, the OS created all processes
– But it can be useful to allow one running
process to create another
• This action is called process spawning
Process Creation
• When one process spawns another,
– Parent Process is the original, creating,
process
– Child Process is the new process
• The related processes need to
communicate and cooperate with each
other.
Process Termination
• There must be some way that a process
can indicate completion.
• This indication may be:
– A HALT instruction generating an interrupt
alert to the OS.
– A user action (e.g. log off, quitting an
application)
– A fault or error
– Parent process terminating
Five-State
Process Model
Five-State
Process Model
• Some processes in the Not Running state are
ready to execute, while others are blocked,
waiting for an I/O operation to complete.
• Using a single queue, the dispatcher could not
just select the process at the oldest end of the
queue.
• Rather, the dispatcher would have to scan the
list looking for the process that is not blocked
and that has been in the queue the longest.
Five-State
Process Model
• A natural way to handle this situation is to split
the Not Running state into two states:
-Ready
-Blocked
• The five states are as follows:
1. Running
The process that is currently being executed.
2. Ready
A process that is prepared to execute when
given the opportunity.
Five-State
Process Model
3. Blocked/Waiting
A process that cannot execute until some event
occurs, such as the completion of an I/O
operation.
4. New
A process that has just been created but has
not yet been admitted to the pool of executable
processes by the OS. (Process control block is
created.)
Five-State
Process Model
5. Exit
A process that has been released from the pool
of executable processes by the OS, either
because it halted or because it aborted for some
reason.
Five-State
Process Model
• The process is in New state means that
the OS has performed the necessary
housekeeping actions to create the
process but the process has not
committed itself for the execution.
• While the process is in the New state,
the program remains in secondary
storage, and concerning information is
needed by the OS of that process is in
main memory.
Five-State
Process Model
• Five state process model indicates the
types of events that lead to each state
transition for a process, the possible
transition are as follows:
– Null → New
– New → Ready
– Ready → Running
– Running → Exit
– Running → Ready
Five-State
Process Model
– Running → Blocked
– Blocked → Ready
– Ready → Exit
– Blocked → Exit
Using Two Queues
Multiple Blocked Queues
Suspended Processes
• Processor is faster than I/O so all
processes could be waiting for I/O
– Swap these processes to disk to free up more
memory and use processor on more
processes
• Blocked state becomes suspend state
when swapped to disk
• Two new states
– Blocked/Suspend
– Ready/Suspend
Suspended Processes
• Blocked/Suspend
The process is in secondary memory and
awaiting an event.

• Ready/Suspend
The process is in secondary memory but
is available for execution as soon as it is
loaded into main memory.
One Suspend State
Two Suspend States
Two Suspend States
• From the previous figure important new
transitions are the following:
– Blocked → Blocked/Suspend
– Blocked/Suspend → Ready/Suspend
– Ready/Suspend → Ready
– Ready → Ready/Suspend
– New → Ready/Suspend
– Blocked/Suspend → Blocked
– Running → Ready/Suspend
– Any State → Exit
Reason for Process
Suspension
Reason Comment
Swapping The OS needs to release sufficient main memory to
bring in a process that is ready to execute.
Other OS Reason OS suspects process of causing a problem.
Interactive User e.g. debugging or in connection with the use of a
Request resource.
Timing A process may be executed periodically (e.g., an
accounting or system monitoring process) and may
be suspended while waiting for the next time.
Parent Process A parent process may wish to suspend execution of
Request a descendent to examine or modify the suspended
process, or to coordinate the activity of various
descendants.
Table 3.3 Reasons for Process Suspension
Roadmap
– How are processes represented and
controlled by the OS. (3.1)
– Process states which characterize the
behaviour of processes. (3.2)
– Data structures used to manage
processes. (3.3)
– Ways in which the OS uses these data
structures to control process execution. (3.4)
– Discuss process management in UNIX
SVR4.(3.7)
3.3 Process Description
• The OS is the entity that manages the use
of system resources by processes.
• In a multiprogramming environment, there
are number of processes (P1, … , Pn) that
have been create d and exist in virtual
memory.
• Each process, during the course of its
execution, needs access to system
resources, including the processor, I/O
devices, and main memory.
Process Description
Process Description
• In the previous figure, process P1 is
running.
• Process P2 is in main memory but it is
blocked waiting for I/O device allocated to
P1.
• Process Pn has been swapped out and is
therefore suspended.
Operating System
Control Structures
• For the OS is to manage processes and
resources, it must have information about
the current status of each process and
resource.
• Tables are constructed for each entity the
operating system manages.
OS Control Tables
OS Control Tables
• Previous figure shows four different types
of tables maintained by the OS:
– Memory Tables
– I/O Tables
– File Tables
– Process Tables
Memory Tables
• Memory tables are used to keep track of
both main and secondary memory.
• Must include this information:
– Allocation of main memory to processes
– Allocation of secondary memory to processes
– Protection attributes for access to shared
memory regions
– Information needed to manage virtual memory
I/O Tables
• Used by the OS to manage the I/O
devices and channels of the computer.
• The OS needs to know
– Whether the I/O device is available or
assigned
– The status of I/O operation
– The location in main memory being used as
the source or destination of the I/O transfer
File Tables
• These tables provide information about:
– Existence of files
– Location on secondary memory
– Current Status
– other attributes.
• Sometimes this information is maintained
by a file management system.
Process Tables
• To manage processes the OS needs to
know details of the processes
– Current state
– Process ID
– Location in memory
– etc
Process Control Structures
• Consider what the OS must know if it is to
manage and control a process.
• First, it must know the where the process
is located.
• Second, it must know the attributes of
the process that are necessary for its
management(e.g., process Id and process
state).
1) Process Location
• A process must include a program or set of
programs to be executed.
• Associated with these programs is a set of
data locations for local and global variables
and any defined constants.
• The execution of a program typically
involves a stack that is used to keep the
track of procedure calls and parameter
passing between procedures.
1) Process Location
• Each process has associated with it a
number of attributes that are used by the
OS for process control.
• The collection of attributes is referred to as
a process control block (PCB).
• The collection of program, data, stack, and
attributes is referred as process image.
1) Process Location
• The location of a process image will
depend on the memory management
scheme being used.
– Continuous block of memory
– Noncontiguous memory support (Used by
modern OS)
2) Process Attributes
• We can group the process control block
information into three general categories:
– Process identification
– Processor state information
– Process control information
Process Identification
• Each process is assigned a unique
numeric identifier.
• Many of the other tables controlled by the
OS may use process identifiers to cross-
reference process tables.
Processor State
Information
• This consists of the contents of processor
registers.
– User-visible registers
– Control and status registers
– Stack pointers
• Program status word (PSW)
– contains status information
– Example: the EFLAGS register on Pentium
processors
Pentium II
EFLAGS Register

Also see Table 3.6


Process Control
Information
• This is the additional information needed
by the OS to control and coordinate the
various active processes.
– Scheduling and State Information
– Data Structuring
– Interprocess Communication (IPC)4
– Process Privileges
– Memory Management
– Resource Ownership and Utilization
Structure of Process
Images in Virtual Memory
Role of the
Process Control Block
• The most important data structure in an
OS
– It defines the state of the OS
• Process Control Block requires protection
– A faulty routine could cause damage to the
block destroying the OS’s ability to manage
the process
– Any design change to the block could affect
many modules of the OS
Roadmap
– How are processes represented and controlled
by the OS. (3.1)
– Process states which characterize the
behaviour of processes. (3.2)
– Data structures used to manage processes.
(3.3)
– Ways in which the OS uses these data
structures to control process
execution.(3.4)
– Discuss process management in UNIX
SVR4.(3.7)
3.4 Process Control
Modes of Execution
• Most processors support at least two
modes of execution
• User mode
– Less-privileged mode
– User programs typically execute in this mode
• System mode
– More-privileged mode
– Kernel of the operating system
Modes of Execution
• It is necessary to protect the OS and key
operating system tables, such as process
control blocks, from interference by user
programs.
• In the kernel mode, the software has
complete control of the processor and all
its instructions, registers and memory.
Modes of Execution
• Two question arise:
How does the processor know in which mode it
is to be executing?
How is the mode changed?
• The answer of first question, there is a bit
in the program status word (PSW) that
indicates the mode of execution.
• This bit is changed in response to certain
events.
Modes of Execution
• The answer of second question is, When
a user makes a call to an operating system
service or when an interrupt triggers an
execution of an operating system routine,
the mode is set to kernel mode and, upon
return from the service to the user
process, the mode is set to user mode.
Process Creation
• Once the OS decides to create a new
process it:
– Assigns a unique process identifier
– Allocates space for the process
– Initializes process control block
– Sets up appropriate linkages
– Creates or expand other data structures
Switching Processes
• Several design issues are raised regarding
process switching
– What events trigger a process switch?
– We must distinguish between mode switching
and process switching.
– What must the OS do to the various data
structures under its control to achieve a
process switch?
When to switch processes
A process switch may occur any time that the OS has gained control from the
currently running process. Possible events giving OS control are:

Mechanism Cause Use


Interrupt External to the execution of Reaction to an asynchronous
the current instruction external event

Trap Associated with the execution Handling of an error or an


of the current instruction exception condition
Supervisor call Explicit request Call to an operating system
function

Table 3.8 Mechanisms for Interrupting the Execution of a Process


When to switch processes
• With an ordinary interrupt, control is first
transferred to an interrupt handler, which
does some basic housekeeping and then
branches to an OS routine that is
concerned with the particular type of
interrupt that has occurred.
– Clock interrupt
– I/O interrupt
– Memory fault
When to switch processes
• With a trap, the OS determines if the error
or exception condition is fatal.
• If so, then currently running process is
moved to the Exit state and process switch
occurs.
• Finally, the OS may be activated by a
supervisor call from the program being
executed.
Mode Switching
• In the instruction cycle, in the interrupt
stage, the processor checks to see if any
interrupts are pending, indicated by the
presence of an interrupt signal.
• If no interrupts are pending, the processor
proceeds to the fetch stage and fetches
the next instruction of the current program
in the current process.
Mode Switching
• If an interrupt is pending, the process does
the following:
1. It sets the program counter to the staring
address of an interrupt handler program.
2. It switches from user mode to kernel mode
so that the interrupt processing code may
include privileged instruction.
Mode Switching
• At this point, the context of the process
that has been interrupted is saved into the
that PCB of the interrupted program.
• In most OS, the occurrence of an interrupt
does not necessarily mean a process
switch.
• It is possible that, after the interrupt
handler has executed, the currently
running process resume execution.
Change of
Process State
• A mode switch may occur without hanging
the state of the process that is currently in
Running state.
• In that case, the context saving and
subsequent restoral involve little overhead.
• If the currently running process is to be
moved to another state, then the OS must
make changes in its environment. The
steps involved in a full process switch are
as follows:
Change of
Process State …
• The steps in a process switch are:
1. Save context of processor including program
counter and other registers
2. Update the process control block of the
process that is currently in the Running state
3. Move process control block to appropriate
queue – ready; blocked; ready/suspend
Change of
Process State cont…
4. Select another process for execution
5. Update the process control block of the
process selected
6. Update memory-management data
structures
7. Restore context of the selected process
Thus, the process switch, which
involves a state change, requires more
effort that a mode switch.
Roadmap
– How are processes represented and
controlled by the OS.(3.1)
– Process states which characterize the
behaviour of processes.(3.2)
– Data structures used to manage
processes.(3.3)
– Ways in which the OS uses these data
structures to control process execution. (3.4)
– Discuss process management in UNIX
SVR4.(3.7)
Unix SVR4
System V Release 4

• Uses the model of fig3.15b where most of


the OS executes in the user process

• UNIX uses two categories of processes:


– System processes
– User processes
Unix SVR4
System V Release 4
• System Processes - Kernel mode only
• User Processes
– User mode to execute user programs and
utilities
– Kernel mode to execute instructions that
belong to the kernel.
UNIX Process State
Transition Diagram
UNIX Process States
UNIX Process States
• Two processes are unique in UNIX.
– Process 0 is a special process that is created
when the system boots.
– Process 0 spawns process 1, referred to as
the init process, all other processes in the
system have process 1 as an ancestor.
Process Description
• A process in UNIX is a set of data
structures that provide the OS with all of
the information necessary to manage and
dispatch processes.
• See Table 3.10 which organizes the
elements into three parts:
– user-level context,
– register context, and
– system-level context.
Process Description
1. User-Level Context
• The user-level context contains the basic
elements of a user’s program and can be
generated directly from a compiled object
file.
• The user’s program is separated into text
and data areas.
Process Description
• While the process is executing, the
processor uses the user stack area for
procedure calls and returns and
parameter passing.
• The shared memory area is a data
structure that is shared with other
processes and used for interprocess
communication.
Process Description
2. Register Context
• When a process is not running, the
processor status information is stores in
the register context area.
• Program counter contains the address
of next instruction toe executed.
• Process status register contains the
hardware status at the time of
preemption.
Process Description
• Stack pointer points to the top of the
kernel or user stack depending on the
mode of operation at the time or
preemption.
• General-purpose registers are
hardware dependent.
Process Description
3. System-Level Context
• The system-level context contains the
remaining information that the OS needs
to manage the process.
• It consists of a static part, which is a fixed
in size and stays with a process
throughout its lifetime, and a dynamic part,
which varies in size through the life of the
process.
Process Description
• One element of static part is process
table entry which define the state of a
process , this information is always
accessible to the OS.
• The other element is U (user) area that
also contains additional process control
information that is needed by the kernel
when it is executing in the context of this
process.
Process Description
• The third static portion of the system-level
context is the per process region table,
which is used by the memory
management system.
• Finally the kernel stack is the dynamic
portion of the system-level context. This
stack is used when the process is
executing in kernel mode and contains the
information that must be saved and
restored as procedure calls and interrupt
occur.
Process Creation
• Process creation is by means of the kernel
system call,fork( ).
• This causes the OS, in Kernel Mode, to:
1. Allocate a slot in the process table for the
new process.
2. Assign a unique process ID to the child
process.
3. Copy of process image of the parent, with
the exception of any shared memory.
Process Creation
cont…
4. Increment the counters for any files owned
by the parent, to reflect that an additional
process now also owns those files.
5. Assign the child process to the Ready to
Run state.
6. Returns the ID number of the child to the
parent process, and a 0 value to the child
process.
After Creation
• After creating the process the Kernel can
do one of the following, as part of the
dispatcher routine:
– Stay in the parent process. Control returns to
use mode at the point of the fork call of the
parent
– Transfer control to the child process. The child
process begins executing at the same point in
the code as the parent
After Creation
– Transfer control to another process. Both
parent and child are left in the Ready to Run
state.
• When the return from the fork occurs, the
return parameter is tested. If the value is
zero, then this is the child process.
• If the value is nonzero, then this is the
parent process, and the main line of
execution can continue.
Chapter 4
Threads

Prepared By: Miss K.N.Dandhwani


Roadmap
• Threads: Resource ownership and
execution (4.1)
4.1 Processes and Threads
• Processes have two characteristics:
– Resource ownership - process includes a
virtual address space to hold the process
image
– Scheduling/execution - follows an execution
path(trace) that may be interleaved with other
processes
• These two characteristics are treated
independently by the operating system.
Processes and Threads
• The unit of dispatching is referred to as a
thread or lightweight process.
• The unit of resource ownership is referred
to as a process or task.
Multithreading
• The ability of an OS
to support multiple,
concurrent paths of
execution within a
single process.
Single Thread
Approaches
• MS-DOS supports a
single user process
and a single thread.
• Some UNIX, support
multiple user
processes but only
support one thread
per process.
Multithreading
• Java run-time
environment is a
single process with
multiple threads.
• Multiple processes
and threads are found
in Windows, Solaris,
and many modern
versions of UNIX.
Processes
• In a multithreaded environment, a process
is defined as the unit of resource allocation
and a unit of protection. The following are
associated with processes:
– A virtual address space which holds the
process image
– Protected access to
• Processors,
• Other processes,
• Files,
• I/O resources
One or More Threads in
Process
• Each thread has
– An execution state (running, ready, etc.)
– Saved thread context when not running
– An execution stack
– Some per-thread static storage for local
variables
– Access to the memory and resources of its
process (all threads of a process share this)
One view…

• One way to view a thread is as an


independent program counter operating
within a process.
Threads vs. processes
Benefits of Threads
• Takes less time to create a new thread
than a process
• Less time to terminate a thread than a
process
• Switching between two threads takes less
time that switching processes
• Threads can communicate with each other
– without invoking the kernel
Thread use in a
Single-User System
• Foreground and background work
For example, in a spreadsheet program, one
thread could display menus and read user input,
while another thread executes user commands
and updates the spreadsheet.
• Asynchronous processing
For example, as a protections against power
failure, one can design a word processor to write
its RAM buffer to disk once every minute.
Thread use in a
Single-User System
• Speed of execution
- On thread can compute one batch of data
while another thread reading the next batch
from a device.
- On a multiprocessor system, multiple threads
from the same process may be able to
execute simultaneously.
- Even though one thread may be blocked for
an I/O operation to read in a batch of data,
another thread may be executing.
Thread use in a
Single-User System
• Modular program structure
Threads make it easier to design programs
which involve a variety of activities or a variety of
sources and destinations of input and output.
Threads
• Several actions that affect all of the
threads in a process
– The OS must manage these at the process
level.
• Examples:
– Suspending a process involves suspending all
threads of the process
– Termination of a process, terminates all
threads within the process
Activities similar
to Processes
• Threads have execution states and may
synchronize with one another.
– Similar to processes
• We look at these two aspects of thread
functionality in turn.
– States
– Synchronization
Thread Execution States
• States associated with a change in thread
state
– Spawn (another thread)
– Block
• Issue: will blocking a thread block other, or all,
threads
– Unblock
– Finish (thread)
• Deallocate register context and stacks
Example:
Remote Procedure Call
• Consider:
– A program that performs two remote
procedure calls (RPCs)
– to two different hosts
– to obtain a combined result.
RPC
Using Single Thread
RPC Using
One Thread per Server
Multithreading
on a Uniprocessor
Thread Synchronization
• All of the threads of a process share the
same address space and other resources,
such as open files.
• Any alteration of a resource by one thread
affects the environment of the other
threads in the same process.
• So, it is necessary to synchronize the
activities of the various threads so that
they do not interface with each other or
corrupt data structures.
Thread Synchronization
• For example, if two threads each try to add
an element to a doubly linked list at the
same time, one element may be lost or
the list may end up malformed.
Example - Adobe PageMaker
Categories of
Thread Implementation
• There are two broad categories of thread
implementation :
– User Level Thread (ULT)
– Kernel level Thread (KLT) also called:
• kernel-supported threads
• lightweight processes.
User-Level Threads
• All thread management
is done by the
application.
• The kernel is not aware
of the existence of
threads.
User-Level Threads
• Any application can be programmed to be
multithread by using a threads library,
which is a package of routines for ULT
management.
• The threads library contains code for
creating and destroying threads, for
passing messages and data between
threads, for scheduling thread execution,
and for saving and restoring thread
contexts.
Relationships between ULT
Thread and Process States
Advantages of ULTs
1. Thread switching does not require kernel
mode privileges. This saves the overhead
of two mode switches.
2. Scheduling can be application specific.
3. ULTs can run on any OS. No changes are
required to the kernel to support ULTs.
Disadvantages of ULTs
1. In a typical OS, many system calls are
blocking. As a result, when a ULT
executes a system call, not only is that
thread blocked, but also all of the threads
within the process are blocked.
2. In a pure ULT strategy, a multithreaded
application cannot take advantage of
multiprocessing.
• There are two ways to solve these two
problems:
1. By writing the application as multiple
processes rather than multiple threads.
2. Another way to overcome the problem of
blocking threads is to use a technique
referred to as jacketing.
• The purpose of jacketing is to convert a
blocking system call into a nonblocking
system call.
• For example, instead of directly calling a
system I/O routine, a thread calls an
application-level I/O jacket routine.
• Within this jacket routine is code that
checks to determine if the I/O device is
busy.
• If it is, the thread enters the Blocked state
and passes control to another thread.
When this thread later is given control
again, the jacket routine checks the I/O
device again.
Kernel-Level Threads
• Kernel maintains context
information for the
process and the threads
– No thread management
done by application
• Scheduling is done on a
thread basis
• Windows is an example
of this approach
Advantages of KLT
• The kernel can simultaneously schedule
multiple threads from the same process on
multiple processors.
• If one thread in a process is blocked, the
kernel can schedule another thread of the
same process.
• Kernel routines themselves can be
multithreaded.
Disadvantage of KLT
• The transfer of control from one thread to
another within the same process requires
a mode switch to the kernel.
Combined Approaches
• Thread creation done in
the user space
• Bulk of scheduling and
synchronization of
threads by the
application

• Example is Solaris
Relationship Between
Thread and Processes

Potrebbero piacerti anche