Chapter 1..... 4 OS
Chapter 1..... 4 OS
COLLEGE OF INFORMATICS
DEPARTMENT OF Information Technology
FUNDAMENTAL OF OPERATING SYSTEM (InTc 2022)
1
Chapter 1 :- System Software
Unit Structure
Objectives
Introduction
Definition of operating system
Functions of Operating System
Operating System as User Interface
I/O System Management
Assembler ,Compiler , Loader
History of Operating System
Summary
Model questions
2
Objectives
After going through this unit, you will be able to:
Describe Basic Organization of Computer Systems
Define Operating system, functions, history and
Evolution
Define assembler, linker, loader, compiler
3
Introduction
An operating system act as an intermediary between the user
of a computer and computer hardware. The purpose of an
operating system is to provide an environment in which a user
can execute programs in a convenient and efficient manner.
An operating system is a software that manages the computer
hardware. The hardware must provide appropriate mechanisms
to ensure the correct operation of the computer system and to
prevent user programs from interfering with the proper
operation of the system.
4
Definition of Operating Systems
An Operating system is a program that controls the execution
of application programs and acts as an interface between the
user of a computer and the computer hardware.
A more common definition is that the operating system is the
one program running at all times on the computer (usually
called the kernel), with all else being applications programs.
An Operating system is concerned with the allocation of
resources and services, such as memory, processors, devices
and information.
The Operating System correspondingly includes programs to
manage these resources, such as a traffic controller, a
scheduler, memory management module, I/O programs, and a
file system.
5
Functions of Operating System
Operating system performs three functions:
Convenience: An OS makes a computer more convenient to
use.
Efficiency: An OS allows the computer system resources to
be used in an efficient manner.
Ability to Evolve: An OS should be constructed in such a
way as to permit the effective development, testing and
introduction of new system functions without at the same time
interfering with service
6
Operating System as User Interface
Every general purpose computer consists of the hardware,
operating system, system programs, application programs.
The hardware consists of memory, CPU, ALU, I/O devices,
peripheral device and storage device.
System program consists of compilers, loaders,editors,OS
The application program consists of business program,
database program.
The fig. 1.1 shows the conceptual view of a computer system
7
Cont…
9
Cont
…
Every computer must have an operating system to run other
programs. The operating system and coordinates the use of the
hardware among the various system programs and application
program for a various users.
Operating system
• provides an environment within which other programs can
do useful work.
• is a set of special programs that run on a computer system
that allow it to work properly.
• is the fundamental piece of software and runs in kernel
mode. In this mode it has a complete access to all the
hardware and can execute any instruction the machine is
capable of executing. The rest of the software runs in user
mode in which only a subset of the machine instruction is
available.
10
Cont
…
11
Cont
…
Goal of operating system
OS is designed to serve the following purposes :
1) . Resource Management: Disk, CPU cycles, etc. must be managed
efficiently to maximize overall system performance. It controls
the allocation and use of the computing system‘s resources among
the various user and tasks.
2) . Resource Abstraction: Software interface to simplify use of
hardware resources . It provides an interface between the computer
hardware and the programmer that simplifies and makes feasible for
coding, creation, debugging of application programs
3) Virtualization: Supports resource sharing – gives each process the
appearance of an unshared resource
12
Cont
…
13
I/O System Management
The module that keeps track of the status of devices is called
the I/O traffic controller.
Each I/O device has a device handler that resides in a
separate process associated with that device.
The I/O subsystem consists of
14
Assembler
Input to an assembler is an assembly language program.
Output is an object program plus information that enables the
loader to prepare the object program for execution.
At one time, the computer programmer had at his disposal a
basic machine that interpreted, through hardware, certain
fundamental instructions.
He would program this computer by writing a series of ones
and zeros(machine language), place them into the memory of
the machine.
15
Compiler
The high level languages – examples are FORTRAN,
COBOL, ALGOL and PL/I – are processed by compilers and
interpreters.
A compilers is a program that accepts a source program in a
―high-level language‖ and produces a corresponding object
program.
An interpreter is a program that appears to execute a source
program as if it was machine language. The same name
(FORTRAN, COBOL etc) is often used to designate both a
compiler and its associated language.
16
Loader
A loader is a routine that loads an object program and
prepares it for execution. There are various loading
schemes: absolute, relocating and direct-linking.
In general, the loader must load, relocate, and link the
object program. Loader is a program that places
programs into memory and prepares them for execution.
In a simple loading scheme, the assembler outputs the
machine language translation of a program on a
secondary device and a loader is placed in core.
The loader places into memory the machine language
version of the user‘s program and transfers control to it.
Since the loader program is much smaller than the
assembler, those makes more core available to user‘s
program.
17
History of Operating System
Operating systems have been evolving through the years.
Following table shows the history of OS.
18
History of Operating Systems
The 1940's - First Generations
◦ The earliest electronic digital computers had no operating systems.
◦ Machines of the time were so primitive that programs were often
entered one bit at time on rows of mechanical switches (plug boards).
◦ Programming languages were unknown (not even assembly languages).
◦ Operating systems were unheard of.
The 1950's - Second Generation
◦ By the early 1950's, the routine had improved somewhat with the
introduction of punch cards. The General Motors Research
Laboratories
implemented the first operating systems in early 1950's for their IBM
701.
◦ The system of the 50's generally ran one job at a time.
19
Cont…
The 1960's - Third Generation
◦ The systems of the 1960's were also batch processing systems,
but they were able to take better advantage of the computer's
resources by running several jobs at once.
Fourth Generation
20
Summary
An Operating system is concerned with the allocation of resources and
services, such as memory, processors, devices and information. The
Operating System correspondingly includes programs to manage these
resources, such as a traffic controller, a scheduler, memory management
module, I/O programs, and a file system.
Assembler
Input to an assembler is an assembly language program. Output is an
object program plus information that enables the loader to prepare the
object program for execution.
Loader
A loader is a routine that loads an object program and prepares it for
execution. There are various loading schemes: absolute, relocating and
direct-linking. In general, the loader must load, relocate, and link the object
program
Compilers
A compilers is a program that accepts a source program ‖ in a high- level
language‖ and produces a corresponding object program.
21
Model Question
Q. 1 Define Operating System?
Q. 2 Explain various function of operating system?
Q. 3 Explain I/O system Management?
Q. 4 Define & explain Assembler, Loader,
Compiler?
22
Chapter 2
Fundamental of Operating System
Unit Structure
Objectives
Introduction
Operating System Services
Operating System Components
Batch System
Time Sharing System
Multiprogramming
Spooling
Properties of Operating System
Summary
Model Question
23
Objectives
24
Introduction
An operating system provides the environment within which
programs are executed. Internally, operating systems vary
greatly in their makeup, since they are organized along many
different lines.
The design of a new operating system is a major task. It is
important that the goals of the system be well defined before
the design begins.
We can view an operating system from several vantage points.
One view focuses on the services that the system provides,
another, on the interface that it makes available to users and
programmers; a third, on its components and their
interconnections.
25
Operating System Services
An operating system provides services to programs and to
the users of those programs. It provided by one environment
for the execution of programs. The services provided by one
operating system is difficult than other operating system.
Operating system makes the programming task easier.
The common service provided by the operating system is
listed below.
1. Program execution
2. I/O operation
3. File system manipulation
4. Communications
5. Error detection
26
Cont…
1. Program execution: Operating system loads a program into memory and
executes the program. The program must be able to end its execution,
either normally or abnormally.
2. I/O Operation : I/O means any file or any specific I/O device. Program
may require any I/O device while running. So operating system must
provide the required I/O.
3. File system manipulation : Program needs to read a file or write a file.
The operating system gives the permission to the program for operation on
file.
4. Communication : Data transfer between two processes is required for
some time. The both processes are on the one computer or on different
computer but connected through computer network. Communication may
be implemented by two methods:
a. Shared memory
b. Message passing.
5. Error detection : error may occur in CPU, in I/O devices or in the
memory hardware. The operating system constantly needs to be aware of
possible errors. It should take the appropriate action to ensure correct and
consistent computing. Operating system with multiple users provides
following services: 1. Resource Allocation
2. Accounting
3. Protection
27
Cont…
1) Resource Allocation :
If there are more than one user or jobs running at the same time, then
resources must be allocated to each of them. Operating system manages
different types of resources require special allocation code, i.e. main
memory, CPU cycles and file storage.
There are some resources which require only general request and release
code. For allocating CPU, CPU scheduling algorithms are used for better
utilization of CPU. CPU scheduling algorithms are used for better
utilization of CPU. CPU scheduling routines consider the speed of the
CPU, number of available registers and other required factors.
2) Accounting :
Logs of each user must be kept. It is also necessary to keep record of which
user how much and what kinds of computer resources. This log is used for
accounting purposes.
The accounting data may be used for statistics or for the billing. It also used
to improve system efficiency.
3) Protection :
Protection involves ensuring that all access to system resources is
controlled. Security starts with each user having to authenticate to the
system, usually by means of a password. External I/O devices must be also
protected from invalid access attempts.
In protection, all the access to the resources is controlled. In multiprocess
environment, it is possible that, one process to interface with the other, or
with the operating system, so protection is required. 28
System Calls and System Programs
System calls provide the interface between a process
and the operating system.
These calls are generally available as assembly-
language instructions, and are usually listed in the
manuals used by assembly-language programmers.
29
Operating System Components
Modern operating systems share the goal of supporting
the system components. The system components are :
Process Management
Main-Memory Management
Secondary-Storage Management
I/O System Management
File Management
Protection System
Networking
Command-Interpreter System
30
Cont
…
Process Management
Main-Memory Management
Memory is a large array of words or bytes, each with its own
address. It is a repository of quickly accessible data shared by
the CPU and I/O devices.
The major activities of an operating system in regard to
memory-management are:
o Keep track of which part of memory are currently being
used and by whom.
o Decide which processes are loaded into memory when
memory space becomes available.
o •Allocate and deallocate memory space as needed..
32
Cont
…
33
Cont
…
File Management
35
Networking(Distributed system)
36
Cont
… Command-Interpreter System
37
Batch System
Some computer systems only did one thing at a time. They
had a list of the computer system may be dedicated to a
single program until its completion, or they may be
dynamically reassigned among a collection of active
programs in different stages of execution.
Batch operating system is one where programs and data
are collected together in a batch before processing starts.
A job is predefined sequence of commands, programs and
data that are combined in to a single unit called job.
Memory management in batch system is very simple.
Memory is usually divided into two areas : Operating
system and user program area.
38
Cont
…
39
Cont
…
Advantages of Batch System
Move much of the work of the operator to the computer.
Increased performance since it was possible for job to
start as soon as the previous job finished.
Disadvantages of Batch System
Turn around time can be large from user standpoint.
Difficult to debug program.
A job could enter an infinite loop.
A job could corrupt the monitor, thus affecting pending
jobs.
Due to lack of protection scheme, one batch job can
affect pending jobs.
40
Time Sharing System
41
Cont…
43
Multiprogramming
When two or more programs are in memory at the same time,
sharing the processor is referred to the multiprogramming
operating system. Multiprogramming assumes a single processor
that is being shared. It increases CPU utilization by organizing
jobs so that the CPU always has one to execute.
The operating system keeps several jobs in memory at a time. This
set of jobs is a subset of the jobs kept in the job pool. The
operating system picks and begins to execute one of the job in the
memory. Multiprogrammed system provide an environment in
which the various system resources are utilized effectively, but
they do not provide for user interaction with the computer system.
Jobs entering into the system are kept into the memory. Operating
system picks the job and begins to execute one of the job in the
memory.
44
Cont…
45
Spooling
Acronym for simultaneous peripheral operations on line.
Spooling refers to putting jobs in a buffer, a special area in memory or on
a disk where a device can access them when it is ready.
Spooling is useful because device access data that different rates. The
buffer provides a waiting station where data can rest while the slower
device catches up. Fig 2.3 shows the spooling.
46
Cont…
47
Essential Properties of the Operating System
Batch : Jobs with similar needs are batched together and run through
the computer as a group by an operator or automatic job sequencer.
Performance is increased by attempting to keep CPU and I/O devices
busy at all times through buffering , off line operation, spooling and
multiprogramming. A Batch system is good for executing large jobs
that need little interaction, it can be submitted and picked up latter.
Time sharing : Uses CPU s scheduling and multiprogramming to
provide economical interactive use of a system. The CPU switches
rapidly from one user to another i.e. the CPU is shared between a
number of interactive users. Instead of having a job defined by
spooled card images, each program reads its next control instructions
from the terminal and output is normally printed immediately on the
screen.
Interactive : User is on line with computer system and interacts
with it via an interface. It is typically composed of many short
transactions where the result of the next transaction may be
unpredictable. Response time needs to be short since the user
submits and waits for the result.
48
Cont…
49
Summary
An operating system provides services to programs and to the users of those
programs. It provided by one environment for the execution of programs. The
services provided by one operating system is difficult than other operating
system. Operating system makes the programming task easier.
Batch operating system is one where programs and data are collected
together in a batch before processing starts. In batch operating system memory
is usually divided into two areas : Operating system and user program area.
Time sharing, or multitasking, is a logical extension of multiprogramming.
Multiple jobs are executed by the CPU switching between them, but the
switches occur so frequently that the users may interact with each program
while it is running.
When two or more programs are in memory at the same time, sharing the
processor is referred to the multiprogramming operating system.
Spooling is useful because device access data that different rates. The buffer
provides a waiting station where data can rest while the slower device catches
up.
50
Model Question
Q. 1 Explain various operating system services?
Q. 2 Define Spooling? Describe Spooling process?
Q. 3 Differentiate Multitasking&&Multiprogramming ?
51
Chapter 3
Process Management
Unit Structure
Objectives
Concept of Process (Processes and Programs )
Process State
Suspended Processes
Process Control Block
Process Management (Scheduling Queues and Schedulers)
Context Switching
Operation on processes
Co-operating Processes
Summary
Model Question
52
Objectives
After going through this unit, you will be able to:
To introduce the notion of a process – a program in
execution, which forms the basis of all
computation
To describe the various features of processes,
including scheduling, creation and termination,
and communication.
53
Process concepts
A process is an instance of a program in execution. It encompasses the
static concept of program and the dynamic aspect of execution. As the
process runs, its context (state) changes – register contents, memory
contents, etc., are modified by execution.
process is a sequential program in execution. A process defines the
fundamental unit of computation for the computer. Components of the process
are:
Object program
Data
Resources
Status of the process execution
Object program i.e. code to be executed.
Data is used to for executing the program.
While executing the program, it may require some resources.
Last component(Status of the process execution) is used for verifying
the status of the process execution.
A process can run to completion only when all requested resources have been
allocated to the process. Two or more processes could be executing the same
program each using their own data and resources.
Process exists in a limited span of time.
54
Processes and Programs
Process is a dynamic entity, that is a program in execution. A
process is a sequence of information executions. Process exists
in a limited span of time. Two or more processes could be
executing the same program, each using their own data and
resources.
Program is a static entity made up of program statement.
Program contains the instructions. A program exists at single
place in space and continues to exist. A program does not
perform the action by itself.
55
Cont…
Process state
When process executes, it changes state. Process state is defined as the
current activity of the process.
Process contains five states. Each process is in one of the states
New
Ready
Running
Waiting
Terminated (exit)
• New- a process that has just been created
• Ready- ready processes are waiting to have the processor. Allocating
to them by the operating system so that they can run.
• Running- the process that is currently being executed. A running
process processes all the resources needed for its execution, including
the processor.
• Waiting- a process that can not execute until some event occurs. Such
as the completion of an I/O operation. The running process may
become suspended by invoking an I/O routine.
56
Cont…
Terminated- a process that has been released from
the pool of executable process by the OS.
Fig. 3.1 shows the general form of the process state transition diagram.
57
Cont…
When ever process changes state, the OS reacts by placing the PCB in the
list that corresponds to its new state. Only one process can run on any
processor at any instant and many processes may be in ready and waiting
state.
Suspended processes:- Characteristics of suspended processes
1. Suspended process is not immediately available for execution.
2. The process may or may not be waiting on an event.
3. For preventing the execution, process is suspend by OS, parent
process, process itself and an agent.
4. Process may not be removed from the suspended state until the agent
orders the removal.
• Swapping is used to move all of a process from main memory to
disk. When all the process by putting it in the suspended state and
transferring it to disk.
Reasons for process suspension
1. Swapping
2. Timing
3. Interactive user request
4. Parent process request 58
Cont…
Swapping : OS needs to release required main memory to
bring in a process that is ready to execute.
Timing : Process may be suspended while waiting for the
next time interval.
Interactive user request : Process may be suspended for
debugging purpose by user.
Parent process request : To modify the suspended process
or to coordinate the activity of various descendants.
59
Process Control Block (PCB)
PCB – is the data structure used by the OS. OS groups all
information that needs about a particular process.
PCB- Information associated with each process. which contains :
Process ID (name, number)
Process state
Priority, owner, etc...
Program counter
CPU registers
CPU scheduling information
Memory-management information
Accounting information
I/O status information
60
Fig. 3.2 Process Control Block
Pointer Process State
Process Number
Program Counter
CPU registers
Memory Allocation
Event Information
61
Cont…
Pointer : Pointer points to another process control block. Pointer is used for
maintaining the scheduling list.
Process State : Process state may be new, ready, running, waiting and so on
Program Counter : It indicates the address of the next instruction to be
executed for this process.
Event information : For a process in the blocked state this field contains
information concerning the event for which the process is waiting.
CPU register : It indicates general purpose register, stack pointers, index
registers and accumulators etc. number of register and type of register totally
depends upon the computer architecture.
Memory Management Information : This information may include the value
of base and limit register. This information is useful for deallocating the
memory when the process terminates.
Accounting Information : This information includes the amount of CPU and
real time used, time limits, job or process numbers, account numbers
Process control block also includes the information about CPU scheduling,
I/O resource management, file management information, priority and so.
The PCB simply serves as the repository for any information that may vary
from process to process
62
Process Management / Process Scheduling
Multiprogramming operating system allows more than one
process to be loaded into the executable memory at a time and
for the loaded process to share the CPU using time
multiplexing.
The scheduling mechanism is the part of the process
manager that handles the removal of the running process from
the CPU and the selection of another process on the basis of
particular strategy
63
Scheduling Queues
When the process enters into the system, they are put into a job
queue. This queue consists of all processes in the system. The
operating system also has other queues.
Device queue is a queue for which a list of processes waiting for
a particular I/O device. Each device has its own device queue.
Fig. 3.3 shows the queuing diagram of process scheduling. In the
fig 3.3,
queue is represented by rectangular box.
The circles represent the resources that serve the queues.
The arrows indicate the flow of processes in the system.
64
Cont…
66
Two State Process Model
Process may be in one of two states :
a) Running
b) Not Running
When new process is created by OS, that process enters into the
system in the running state.
Processes that are not running are kept in queue, waiting their
turn to execute.
Each entry in the queue is a printer to a particular process.
Queue is implemented by using linked list.
Use of dispatcher is as follows. When a process interrupted, that
process is transferred in the waiting queue. If the process has
completed or aborted, the process is discarded. In either case,
the dispatcher then select a process from the queue to execute.
67
Schedules
Schedulers are of two types.
1. Long Term Scheduler
2. Short Term Scheduler
68
Cont…
Long Term Scheduler
It is also called job scheduler.
Long term scheduler determines which programs are admitted to the
system for processing. Job scheduler selects processes from the queue and
loads them into memory for execution. Process loads into the memory for
CPU scheduler.
The primary objective of the job scheduler is to provide a balanced mix
of jobs, such as I/O bound and processor bound. It also controls the degree
of multiprogramming. If the degree of multiprogramming is stable, then the
average rate of process creation must be equal to the average departure rate
of processes leaving the system.
On same systems, the long term scheduler may be absent or minimal.
Time-sharing operating systems have no long term scheduler. When
process changes the state from new to ready, then there is a long term
scheduler.
I.e. - Long-term scheduler (job scheduler) - selects which processes should
be brought into the ready queue.
- Long-term scheduler is invoked very infrequently (seconds, minutes)
`=> (may be slow). The long-term scheduler controls the degree
of multiprogramming.
69
Cont…
70
Cont…
71
Cont…
Context Switch
Sometimes called process switch
A context switch involves two processes:
◦ One leaves the Running state
◦ Another enters the Running state
The status (context) of one process is saved; the status of the
second process restored.
When CPU switches to another process, the system must save
the state of the old process and load the saved state for the
new process.
Context-switch time is overhead; the system does no useful
work while switching. Time dependent on hardware support.
72
Operation on Processes
Several operations are possible on the process. Process must be created and
deleted dynamically. Operating system must provide the environment for
the process operation. We discuss the two main operations on processes.
A. Create a process
B.Terminate a process
Process Creation
Parent process creates children processes, which, in turn create other
processes, forming a tree of processes.
• When a process creates a new process, two possibilities exist in
terms of execution.
1. The parent continues to execute concurrently with its children.
2. The parent waits until some or all of its children have terminated
73
Cont…
74
Cont…
75
Cont…
Process Termination
Process executes last statement and asks the operating system
to delete it (exit).
Output data from child to parent (via fork).
Process' resources are deallocated by operating system.
Parent may terminate execution of children processes (abort).
Child has exceeded allocated resources.
Task assigned to child is no longer required.
Parent is exiting.
Operating system does not allow child to continue if its parent
terminates.
Cascading termination.
76
Cont…
77
Co-operating Processes
Co-operating process is a process that can affect or be affected by the
other processes while executing. If suppose any process is sharing data
with other processes, then it is called co-operating process.
Benefit of the co-operating processes are :
1. Sharing of information
2. Increases computation speed
3. Modularity
4. Convenience
Co-operating processes share the information : Such as a file, memory
etc. System must provide an environment to allow concurrent access to
these types of resources. Computation speed will increase if the
computer has multiple processing elements are connected together.
System is constructed in a modular fashion. System function is divided
into number of modules.
78
Summery
A process is a program in execution. As a process executes, it changes
state. The state of a process is defined by that process‘s current activity.
Each process may be in one of the following states: new, ready, running,
waiting, or terminated. Each process is represented in the operating system
by its own process control block (PCB).
A process, when it is not executing, placed in some waiting queue. There
are two major classes of queues in an operating system: I/O request queues
and the ready queue. The ready queue contains all the processes that are
ready to execute and are waiting for the CPU.
Each process is represented by a PCB and the PCBs can be linked together
to form a ready queue. Long-term(job) scheduling is the selection of
processes that will be allowed to contend for the CPU. Normally, long-term
scheduling is heavily influenced by resources-allocation considerations,
especially memory management. Short-term(CPU) scheduling is the
selection of one process from the ready queue.
79
cont…
Operating systems must provide a mechanism for parent processes to create
new child processes. The parent may wait for its children to terminate
before proceeding, or the parent and children may execute concurrently.
There are several reasons for allowing concurrent execution: information
sharing computation speedup, modularity, and convenience.
The processes executing in the operating system may be either independent
processes or cooperating processes. Cooperating processes require an inter-
process communication mechanism to communicate with each other.
Principally, communication is achieved through two schemes: shared
memory and message passing. The shared-memory method requires
communicating processes through
The use of these shared variables. In a shared-memory system, the
responsibility for providing communication rests with the application
programmers: the operating system needs to provide only the shared
memory. The responsibility for providing communication may rest with the
operating system itself. These two schemes are not mutually exclusive and
can be used simultaneously within a single operating system.
80
Model questions
Q.1 Define process and programs?
Q.2 Describe Process Control Block?
Q.3 Explain Scheduling Queues?
Q.4 Explain schedulers and its types?
Q.5 Differentiate various types of scheduler?
Q.6 Explain context switch?
Q.7 Explain operation on processes?
81
Chapter 4 :- Thread management
Unit Structure
Objectives
Introduction Of Thread
Types of Thread (User Level Thread and Kernel Level
Thread)
Advantage of Thread
Multithreading Models
Difference between User Level and Kernel Level Thread
Difference between Process and Thread
Threading Issues
Summary
Model Question
82
Objective
After going through this unit, you will be able to:
To introduce Thread concepts & its types.
To introduce Multithreading Models and Threading issues.
83
Introduction of Thread
A thread is a flow of execution through the process code,
with its own program counter, system registers and stack.
Threads are a popular way to improve application
performance through parallelism. A thread is sometimes
called a light weight process.
Threads represent a software approach to improving
performance of operating system by reducing the over head
thread is equivalent to a classical process. Each thread belongs
to exactly one process and no thread can exist outside a
process. Each thread represents a separate flow of control.
Fig. 4.1shows the single and multithreaded process.
84
Cont….
85
Cont…
A thread (or lightweight process) is a basic unit of CPU utilization;
it consists of:
program counter
register set
stack space
A thread shares with its peer threads its:
code section
data section
operating-system resources
A traditional or heavyweight process is equal to a task with one thread.
In a task containing multiple threads, while one server thread is blocked and
waiting, a second thread in the same task could run.
Cooperation of multiple threads in same job confers higher throughput and
improved performance.
Applications that require sharing a common buffer (producer-consumer
problem) benefit from thread utilization.
Threads provide a mechanism that allows sequential processes to make
blocking system calls while also achieving parallelism.
86
Types of Thread
Threads is implemented in two ways :
1. User Level
2. Kernel Level
User Level Thread
In a user thread, all of the work of thread management is done
by the application and the kernel is not aware of the existence
of threads.
The thread library contains code for creating and destroying
threads, for passing message and data between threads, for
scheduling thread execution and for saving and restoring
thread contexts.
The application begins with a single thread and begins
running in that thread.
User level threads are generally fast to create and manage 87
Cont…
88
Kernel Level Threads
In Kernel level thread, thread management done by the
Kernel. There is no thread management code in the
application area.
Kernel threads are supported directly by the operating
system. Any application can be programmed to be
multithreaded. All of the threads within an application are
supported within a single process.
The Kernel maintains context information for the process as
a whole and for individuals threads within the process.
Scheduling by the Kernel is done on a thread basis. The
Kernel performs thread creation, scheduling and management
in Kernel space. Kernel threads are generally slower to create
and manage than the user threads.
89
Cont…
90
Cont…
Advantages of Thread
1. Thread minimize context switching time.
2. Use of threads provides concurrency within a process.
3. Efficient communication.
4. Economy- It is more economical to create and context
switch threads.
5. Utilization of multiprocessor architectures –
The benefits of multithreading can be greatly increased in a
multiprocessor architecture.
91
Multithreading Models
Some operating system provide a combined user level thread
and Kernel level thread facility. Solaris is a good example of
this combined approach.
In a combined system, multiple threads within the same
application can run in parallel on multiple processors and a
blocking system call need not block the entire process
92
Cont… Difference between User Level
and Kernel Level Thread
User Level Threads Kernel Level Thread
• User level thread are faster to create •Kernel level thread are slower to
and manage create and manage.
• Implemented by a thread library at •Operating system support directly
the user level. to Kernel threads.
• User level thread can run on any •Kernel level threads are specific
operating system. to the operating system.
• Support provided at the user level •Support may be provided by
called user level thread. kernel is called Kernel level
• Multithread application cannot take threads.
advantage of multiprocessing. •Kernel routines themselves can
be multithreaded
93
Cont… Difference between Process and Thread
Process
Process is called heavy weight process.
Process switching needs interface with operating system.
In multiple process implementation each process executes the same code but
has its own memory and file resources.
If one server process is blocked no other server process can execute until the
first process unblocked.
Multiple redundant process uses more resources than multiple threaded.
In multiple process each process operates independently of the others.
Thread
Thread is called light weight process.
Thread switching does not need to call a operating system and cause an
interrupt to the Kernel.
All threads can share same set of open files, child processes.
While one server thread is blocked and waiting, second thread in the same task
could run.
Multiple threaded process uses fewer resources than multiple redundant
process.
One thread can read, write or even completely wipe out another threads stack.
94
Threading Issues
System calls fork and exec is discussed here. In a multithreaded
program environment, fork and exec system calls is changed.
Unix system have two version of fork system calls. One call
duplicates all threads and another that duplicates only the
thread that invoke the fork system call.
Whether to use one or two version of fork system call totally
depends upon the application. Duplicating all threads is
unnecessary, if exec is called immediately after fork system
call.
Thread cancellation is a process of thread terminates before its
completion of task. For example in multiple thread environment
, thread concurrently searching through a database. If any one
thread returns the result, the remaining thread might be
cancelled.
Thread cancellation is of two types.
1. Asynchronous cancellation
2. Synchronous cancellation 95
Cont…
In asynchronous cancellation, one thread immediately
terminates the target thread. Deferred cancellation
periodically check for terminate by target thread. It also
allow the target thread to terminate itself in an orderly
fashion. Some resources are allocated to the thread. If we
cancel the thread, which update the data with other thread.
This problem may face by asynchronous cancellation system
wide resource are not free if threads cancelled
asynchronously.
Most of the operating system allow a process or thread to be
cancelled asynchronously.
96
Summary
A thread is a flow of control within a process. A multithreaded
process contains several different flows of control within the same
address space. The benefits of multithreading include increased
responsiveness to the user, resource sharing within the process,
economy, and scalability issues such as more efficient use of
multiple core.
User level threads are threads are visible to the programmer and are
unknown to the kernel. The operating system kernel supports and
manages kernel level threads. In general, user level threads are faster
to create and manage than are kernel threads, as no intervention from
the kernel is required. Three different types of models relate user and
kernel threads: the many-to-one model maps many user threads to a
single thread. The one to one model maps each user thread to a
corresponding kernel thread. The many to many model multiplexers
many user threads to a smaller or equal number of kernel threads.
97
Model Question
98