Operating Systems
Design & Concepts
March 5, 2024 Operating Systems 1
Objectives
To understand the role of OS, the major
subsystems that make up a modern OS
To appreciate the concepts, structure and
implementation of operating systems.
To appreciate the realization of the
concepts in contemporary operating
systems.
March 5, 2024 Operating Systems 2
What is an Operating System?
Software make a computer system to become alive
Computer Software can be divided into two forms:
System programs
Application programs.
System programs manage the operations of the computer
itself
Application programs perform the work that the user wants.
An Operating System is a fundamental system program
that:
controls all computer resources
provides the base upon which application programs run.
March 5, 2024 Operating Systems 3
What is an Operating System? …
Before the introduction of operating systems, computers
ran one program at a time.
The programmer would write a program (punch card)
and submit it to the operator who would run it.
The programmer would then come for the output later on
(either the real output or dump of errors).
As technology advanced, it became possible to put all the
jobs or programs in a single tape.
The tape is then loaded and manipulated by a another
program (called monitor), which monitors behavior of
the jobs
March 5, 2024 Operating Systems 4
What is an Operating System? …
Apparently, this process was cumbersome and complex
A way had to be found to shield programmers from
complexity of the h/w and allow for sharing of the vast
computer resources.
This solution is to put of a layer of s/w on top of h/w to
manage all resources and provide a virtual machine that is
easier to use and program.
A virtual machine is software that creates an environment
between the computer platform and the end-user.
An Operating System is a resource allocator (CPU time,
memory, file storage, I/O devices etc.).
March 5, 2024 Operating Systems 5
What is an Operating System? …
The concept of an operating system can be illustrated
using the following diagram:
Banking System Airline Web Browser Application Programs
Reservation
Compilers Editors Command
Interpreter
Operating System System Programs
Machine Language
Micro-program Hardware
Physical Devices
March 5, 2024 Operating Systems 6
Functions of Operating System
Operating Systems perform two unrelated functions:
Provision of a virtual machine
Resource management
Provision of a virtual machine
A Programmer does not want to be involved in
programming devices like memory, floppy and hard
disk.
What a programmer needs is a high-level abstraction.
For example, in case of disks, the abstraction is that
the disk contains a collection of files that may be
opened, read, written and closed.
The Operating system provides this abstraction.
March 5, 2024 Operating Systems 7
Functions of Operating System …
Resource Manager
An Operating System provides for orderly and
controlled allocation of CPU, memory and I/O devices
among processes competing for them.
For example, if two processes are competing for the
same printer and the sharing is not controlled, printing
will be interleaved.
Consequently, the OS keeps track of who is using
which resource, grant resource requests, account for
usage and mediate conflicting requests from different
processes.
March 5, 2024 Operating Systems 8
Operating system concepts
The interface between the O/S and user programs is defined by a
set of ‘extended’ instructions that the O/S provides.
These instructions are referred to as system calls.
a) Processes
A process is a program in execution.
Each process has its address space containing the executing
program, its data and stack.
Also associated with each process is a set of registers
(program counter, stack pointer …)
In a time sharing system, when a process is suspended from
the CPU, its context must be saved so that its restarted at
exactly the same state.
March 5, 2024 Operating Systems 9
Operating system concepts …
a) Processes
A suspended program consists of its address space (core
image) and its process table entry.
Key process management system calls are those dealing
with the creation and termination of processes, and
memory management (request/release of memory).
A process can create other processes known as child
processes and these processes can in turn create other
child processes.
Processes at times need to communicate with one another
when cooperating to finish some task.
This is referred to as IPC.
March 5, 2024 Operating Systems 10
Operating system concepts …
b) Files
A file (program or data) is a collection of related
information defined by its creator .
There are system calls for creation, copying,
deletion, movement, reading and writing of files.
For easy access, files are organized into logical
clusters or directories.
For example, you have directories for word
processing documents, spreadsheets, databases,
programs etc.
March 5, 2024 Operating Systems 11
Operating system concepts …
b) Files
Directories give rise to hierarchical file system as shown
below:
Root
Staff Student
James Peter John Andrew
ICS 636 ICS 613 Games Programs
March 5, 2024 Operating Systems 12
Operating system concepts …
b) Files
An absolute name of a file is specified by giving its path
name from the root directory.
Absolute path names consist of the list of directories
traversed from the root directory to get to the file with slashes
separating the components.
For example, in the figure above, the path for the file ICS 613
can be specified by: /Staff/James/ICS613.
The relative path name is specified by giving the path name
of a file from the current directory, for example,
James/ICS613, with current directory /Staff .
March 5, 2024 Operating Systems 13
Operating system concepts …
c) Batch Systems
Early operating systems were batch systems.
Common input devices were card readers and tape drives.
Common output devices were line printers, tape drives and card
punches.
Users would submit their jobs to the operator.
Major task of OS was to transfer control from one job to the
next.
Jobs with similar needs were batched together and run as a
group to speed processing.
The turnaround time in these systems was high.
March 5, 2024 Operating Systems 14
Operating system concepts …
c) Batch Systems
The CPU, is often idle because of the disparity in speed between
it and the I/O devices.
Spooling was introduced to reduce the turnaround time and
CPU idle time in these systems, the spool.
Spooling, in essence uses the disk as a buffer, for reading as far
ahead as possible on input device and for storing output files
until the output device is able to accept them.
d) Multiprogramming
Spooling results in several ready jobs to be put in memory,
selecting the job is referred to as job scheduling.
March 5, 2024 Operating Systems 15
Operating system concepts …
d) Multiprogramming
The OS manages the process of job scheduling i.e. does some
memory management.
The most important aspect of job scheduling is the ability to
multi-program.
The OS picks and executes any of the jobs in memory.
Eventually, a job will wait for some operation such as I/O.
In multiprogramming, when this happens the OS simply
switches to and executes another job.
Making this decision is known as CPU scheduling.
March 5, 2024 Operating Systems 16
Operating system concepts …
e) Time Sharing Systems
Time-sharing, or multitasking is a logical extension of
multiprogramming.
In time-sharing, multiple jobs, are executed by the CPU
switching between so frequently that the users may not
realize.
Time-sharing systems were developed to provide interactive
use of the computer system.
It allows many users to share the computer simultaneously.
As the system switches rapidly from one user to the other,
the user is given the impression that they have their own
computer .
March 5, 2024 Operating Systems 17
Operating system concepts …
f) Timer Interrupts
Programs were given a specified amount of time for their
execution .
The monitor (OS) had the ability to interrupt the program in
case its execution time expired.
g) Virtual Memory
Gives a program the illusion that it has as much memory as it
needs.
A program is divided into pages so that a page is brought in
memory at any given time.
There was shifting of pages depending on the processing
demands.
March 5, 2024 Operating Systems 18
Operating system concepts …
h) Parallel System
Most computers are single process systems
However, the trend is towards having multiprocessing
systems
Such systems have more than one processor in close
communication, sharing the computer bus, clock, memory
and peripheral devices
Motivation for having such systems is to improve the
throughput and reliability of the system.
March 5, 2024 Operating Systems 19
Operating system concepts …
i) Real-Time Systems
Used when there are rigid time requirements on the operation of
a processor or the flow of data and thus often used as a control
device in a dedicated application.
Sensors bring data to the computer.
The computer must analyze the data and possibly adjust control
to modify the sensor inputs.
Examples include: systems that control scientific experiments,
medical imaging systems and industrial control systems.
March 5, 2024 Operating Systems 20
Operating Systems Development
(A Historical perspective)
O/S have developed through a number of phases and are
basically connected to the computer generations
(architecture)
1. First generation (1945 –1955) – Vacuum tubes and
plug boards
First generation computers were basically mechanical
devices.
Computers were programmed manually by setting
switches, plugging and unplugging cables.
Operations of these machines were slow, cumbersome
and tedious.
March 5, 2024 Operating Systems 21
Operating Systems Development
(A Historical perspective) …
The operations of these machines were very slow,
cumbersome and tedious.
‘Stored program’ concept was introduced by Von
Neumann.
Led to the realization of digital computers and the
inception of the programming concept.
The computers had all features of modern computers i.e.
CPU (ALU, Registers), memory and I/O facilities.
Programming was done using machine language.
Each user would be allocated a block of time and
exclusive access at any given time.
March 5, 2024 Operating Systems 22
Operating Systems Development
(A Historical perspective) …
Preparing a machine language program for execution
involved:
Writing a program and operating it directly from the console.
Programs and data would be manually loaded into memory.
Appropriate buttons would be pushed to set the starting
address and start the execution of the program.
In case of errors, programmer halts the program and examine
contents of memory and registers to debug the program.
In the 1950’s
Assembly languages were developed.
Assemblers for compiling Assembly language to machine
language.
Punched cards were used for I/O operations.
March 5, 2024 Operating Systems 23
Operating Systems Development
(A Historical perspective) …
The problems during this time included:
Significant setup time (time taken to load, assemble and
execute programs).
The CPU sat idle for lengths of time, under utilizing the
resources and abilities of the computer.
March 5, 2024 Operating Systems 24
Operating Systems Development
(A Historical perspective) …
2. Second Generation Computers (1955 – 1965) –
Transistors and Batch Systems
Characteristics of Computers and software at this
time:
Used transistors instead of vacuum tubes.
Machine independent languages like COBOL, FORTRAN and
ALGOL became common.
System software like compilers, utilities for tape/card
conversion and batch monitors were made available.
Computers used for scientific and business data processing.
March 5, 2024 Operating Systems 25
Operating Systems Development
(A Historical perspective) …
The problems with the computers:
CPU sat idle for some time due to time reserved and not being
used and slow I/O data transfers.
There was an I/O and computer speed disparity as computers
had become faster than the I/O devices.
Solutions to these problems:
Use of professional operators.
Batching of computer jobs.
Jobs with similar needs were batched together to make use of
available set ups common to them e.g. All COBOL,
FORTRAN.
Use of a rudimentary operating system called batch monitor to
reduce human setup time.
March 5, 2024 Operating Systems 26
Operating Systems Development
(A Historical perspective) …
Solutions to these problems (cont):
Off-line Spooling to supplement batch processing. Tapes rather
than punched cards were used for input.
Multiple buffering was introduced overlapping CPU and I/O
operations . It builds blocks of data into memory before output
and also blocks of data before input to memory.
March 5, 2024 Operating Systems 27
Operating Systems Development
(A Historical perspective) …
3. Third Generation Computers (1965 – 1980) – ICs and
multiprogramming
IC technology replaced transistor technology.
Led to reduction in the cost of computers, size, efficiency,
speed and reliability.
Semi-conductor (IC) memory became common.
Microprogramming came to a wide spread use.
Concurrent programming techniques like time-sharing
and multiprogramming used to share CPU.
Use of magnetic Disks became common.
March 5, 2024 Operating Systems 28
Operating Systems Development
(A Historical perspective) …
The problems during this time:
Change in technology led to I/O and CPU speed disparities
resulting to high CPU idle time.
Poor utilization of the CPU, which had become even faster
resulting in high turnaround times and low throughput.
Solution to these problems:
Introduction of multiprogramming – Memory partitioned, job
loaded to partition and executed, removed from CPU on
performing I/O.
Online Spooling became a common phenomenon - Used together
with magnetic disks which is a DAD.
The desire for applications requiring quick response paved way
for time-sharing .
March 5, 2024 Operating Systems 29
Operating Systems Development
(A Historical perspective) …
Solution to these problems:
Introduction of multiprogramming – Memory partitioned, job
loaded to partition and executed, removed from CPU on
performing I/O.
Online Spooling became a common phenomenon - Used together
with magnetic disks which is a DAD.
The desire for applications requiring quick response paved way
for time-sharing.
Real time systems also became popular.
March 5, 2024 Operating Systems 30
Operating Systems Development
(A Historical perspective) …
4. Fourth Generation Computers (1980 …) – VLSI and
Personal Computers
VLSI led to the possibility of manufacturing a whole
component in a single IC chip.
This made the computers at this time to be fast, reliable,
cheap and efficient.
This led to:
Personal Computers
Parallel Processing systems
Computer Networks
March 5, 2024 Operating Systems 31
Operating Systems Development
(A Historical perspective) …
Personal Computers
Software industries were developed to manufacture the
required software like single user OS for use in personal
computers.
Initially, they were only single user OS
Now we have multitasking operating systems like Windows
’95 where a user runs several tasks concurrently.
These OS have also opted for user convenience and
responsiveness through better user interface (Graphical User
Interface).
March 5, 2024 Operating Systems 32
Operating Systems Development
(A Historical perspective) …
Parallel Processing Systems
Parallel systems make use of more than one processor to
perform tasks.
Operating systems for parallel systems were developed to
efficiently exploit the underlying available hardware.
March 5, 2024 Operating Systems 33
Operating Systems Development
(A Historical perspective) …
Computer Networks
Independent computers interconnected by a n/w to allow users
share resources like printers, servers, plotters and hard disks.
Could also exchange data through the communication
medium.
Networks can be categorized by the geographical they cover.
Consequently, they are divided into LAN (Local Area
Networks) covering a smaller geographical region like a
building or small town and
WAN (Wide Area Networks) covering a larger geographical
region like a city, continent or the entire globe. Network
operating systems were developed to manage computers in a
network.
March 5, 2024 Operating Systems 34
Operating Systems Structure
A system as big as an OS should be engineered carefully
for proper functioning and easy modification.
Common approach is to structure system into small
components rather than monolithic systems.
There are four major operating system designs structures:
1. Monolithic Systems
2. Layered Systems
3. Virtual Machines
4. Client-Server systems
March 5, 2024 Operating Systems 35
Operating Systems Structure …
1. Monolithic Systems
Most common approach also referred to as ‘big mess’.
Frequently these O/S started small then grew big.
O/S written as a collection of procedures which can call any
other procedures.
Each procedure has a well-defined interface in term of the
parameters and results and can call any other when need be.
Individual procedures compiled to build the object code then
bound to a single object code using the system linker.
There is no encapsulation and information hiding as every
procedure is visible to any other.
March 5, 2024 Operating Systems 36
Operating Systems Structure …
1. Monolithic Systems …
System calls are requested by putting parameters in well defined
places such as registers or the stack and then executing a kernel
or supervisor call.
This switches the machine from user mode to kernel mode and
transfer control to the OS.
Most CPUs have two modes:
kernel mode (OS), in which all instructions are allowed and
user mode, for user programs, in which I/O and other instructions are
not allowed.
In this model, user programs make system calls and when
finished, control is given back to the user program.
March 5, 2024 Operating Systems 37
Operating Systems Structure …
1. Monolithic Systems …
MS-DOS is an example of such a system.
Designed and implemented by few big who didn’t know it
would become so popular and grow big.
Written to provide most functionality in in least space, due to
limitation of h/w it ran on.
Not divided into modules carefully.
Interfaces and levels of functionality not well separated.
For example, application programs are able to access basic I/O
to write directly to display and disk drives
March 5, 2024 Operating Systems 38
Operating Systems Structure …
1. Monolithic Systems …
Application Programs
Resident System Programs
MS-DOS Device drivers
ROM BIOS Device Drivers
MS DOS Layer Structure
March 5, 2024 Operating Systems 39
Operating Systems Structure …
2. Layered Systems
OS is broken down into a hierarchy of layers.
Layers are selected such that each uses operations of the lower
level layers only.
Simplifies debugging and system verification.
The advantage of this approach is modularity.
Each layer is constructed upon the layer below it.
The first layered system was THE (built at Technische
Hogeschool Eindhoven) system built in Netherlands.
This system had six layers:
March 5, 2024 Operating Systems 40
Operating Systems Structure …
2. Layered Systems …
Layer Function
5 The operator
4 User Programs
3 I/O management
2 Operator-process communication
1 Memory and Drum management
0 Process allocation and multiprogramming
March 5, 2024 Operating Systems 41
Operating Systems Structure …
2. Layered Systems …
Layer 0 dealt with allocation of the processor or context
switching when timer interrupts occurred.
Layer 1 did memory management.
It allocated space for processes in main memory and pages
(drum)for those that could not fit in memory.
Above layer 1 processes did not have to worry whether they
were in main memory or the drum.
Layer 2 handled communication between each process and the
operator console.
March 5, 2024 Operating Systems 42
Operating Systems Structure …
2. Layered Systems …
Layer 3 took care of managing the I/O devices and buffering the
information streams too and from them.
Layer 4 is where the user programs were found and the system
operator was located in layer 5.
One disadvantage with this approach is that it needs appropriate
definition of various layers as a layer can use only functions of
lower layers.
For example, drives for backing storage must be at lower levels
that those for memory management.
Another disadvantage is that they tend to be less efficient than
other types of approaches.
March 5, 2024 Operating Systems 43
Operating Systems Structure …
3. Virtual Machines
Computer system VM/370 based on the observation that a
time-sharing system provides multiprogramming and an
extended machine with a more convenient interface that the
bare hardware.
This system separates these two functions.
Core of the system is virtual machine monitor running on
bare hardware.
It does multiprogramming, providing not one but several
virtual machines to the next layer up.
Each process is provided with a virtual copy of the
underlying computer.
March 5, 2024 Operating Systems 44
Operating Systems Structure …
3. Virtual Machines …
Unlike other OS, these virtual machines are not extended
machines, but exact copies of the bare hardware including
I/O, interrupts, kernel/user mode and everything else the
real machine has.
Each virtual machine can run any OS that will run directly
on the bare hardware.
Different virtual machines can run different OS.
Some run a single-user, interactive system called CMS
(Conversational Monitor System) for time-sharing users.
March 5, 2024 Operating Systems 45
Operating Systems Structure …
3. Virtual Machines …
A CMS program system call is trapped to the OS in its
own virtual machine, not to VM/370.
CMS then issues the normal hardware I/O instructions.
I/O instructions are then trapped by VM/370.
VM/370 then performs them as part of it simulation of the
real hardware.
This makes a complete separation of the functions of
multiprogramming and providing an extended machine.
Consequently, each of the OS parts can be much simpler,
more flexible, and easier to maintain.
March 5, 2024 Operating Systems 46
Operating Systems Structure …
3. Virtual Machines …
System call
CMS CMS CMS
Trap
I/O
instruction VM/370
Trap
Bare hardware
March 5, 2024 Operating Systems 47
Operating Systems Structure …
4. Client-Server Model
VMS/370 gains much simplicity by moving a larger part
of the traditional OS code (extended machine) into a
higher layer, CMS.
Nevertheless, VMS/370 is still a complex program
because it is difficult to simulate several virtual machines.
Trend in modern O/S is to take this idea even further and
remove as much as possible from the OS, leaving a
minimal kernel.
The approach is to implement most of OS functions in
user processes.
March 5, 2024 Operating Systems 48
Operating Systems Structure …
4. Client-Server Model
For example, to request a block of a file:
client process sends the request to the server process,
server process does the work and sends back the answer.
In this model, the kernel handles the communication
between clients and servers.
By splitting the OS up into parts, each handling one facet
of the system like file service, process service or memory
service, each part becomes small and manageable.
Further, servers run in user mode and not in kernel mode
hence do not have direct access to the H/W.
March 5, 2024 Operating Systems 49
Operating Systems Structure …
4. Client-Server Model
Consequently, a bug in the server process may crash the
server, but not the entire system.
Another advantage is its adaptability to use in distributed
systems
If a client communicates with a server by sending it
messages, the client need not know whether the message is
handled locally or whether it was sent across the network
to a server on a remote machine.
March 5, 2024 Operating Systems 50
Process Management
Modern computers do multitasking.
While executing a program, a computer can also read
from a disk and output text to a screen or a printer.
CPU switches from one process to another.
At any one instance, the CPU runs only one program.
In the course of one second CPU may work on several
programs, thus giving the users the illusion of parallelism
(pseudo-parallelism).
This is in contrast to h/w parallelism of multiprocessor
systems.
March 5, 2024 Operating Systems 51
Process Management
Modern computers do multitasking
While executing a program, a computer can also read
from a disk and output text to a screen or a printer.
CPU switches from one process to another
At any one instance, the CPU runs only one program
In the course of one second CPU may work on several
programs, thus giving the users the illusion of parallelism
(pseudo-parallelism).
This is in contrast to h/w parallelism of multiprocessor
systems.
March 5, 2024 Operating Systems 52
Process Management
Process Concept
A batch system executes jobs, whereas a time-shared
system has user programs or tasks.
Job and process are almost used interchangeably.
Process is an executing program, including the current
values of the program counter, registers and variables.
Execution of a process must proceed in sequential fashion,
one instruction executed per time.
A program by itself is not a process; a program is a
passive entity, whereas a process is an active entity.
March 5, 2024 Operating Systems 53
Process Management
Process Concept …
Two processes may be associated with the same program.
These are considered to be two separate execution
sequences.
For example, several users may be running copies of the
mail program, or the same user may invoke many copies
of the same program.
Each of these is a separate process and their data sections
will vary.
March 5, 2024 Operating Systems 54
Process Management
Process Concept …
Each process has its own virtual CPU.
The CPU in reality does multiprogramming.
In the figure below, we see the computer
multiprogramming four programs in memory.
Four program counters
D
B
A B C D
A
March 5, 2024 Operating Systems 55
Process Management
Process Concept …
The operating systems that support the process concept
must provide some way to create all the processes needed.
In some OS it is possible to have processes present when
the system comes up.
In other OS, some way is needed to create and destroy
processes as the need arises.
Processes need a way of creating other processes.
Each process has one parent, but zero, one, two or more
children.
March 5, 2024 Operating Systems 56
Process Management
Process Creation & Termination
Principal events that cause process creation
System initialization
Execution of a process creation system
User request to create a new process
Initiation of a batch job
Conditions that terminate processes
Normal exit (voluntary)
Error exit (voluntary)
Fatal error (involuntary)
Killed by another process (involuntary)
March 5, 2024 Operating Systems 57
Process Management
Process Concept …
A process blocks because logically it cannot proceed,
typically because it is waiting for input that is not yet
available.
A process that is ready and able to run can also be stopped
because the OS has decided to allocate the CPU to another
process.
A process can be in several states during execution:
Ready (new)
Blocked
Running (terminated)
March 5, 2024 Operating Systems 58
Process Management
Process States
1. Running state, when it is actually using the CPU.
2. Ready state, when it is temporarily stopped to let another
process run.
3. Blocked state, when it is unable to run until some external
event happens. Running
2
1
3
Blocked Ready
March 5, 2024 Operating Systems 59
Process Management
Process States
Transition 1 occurs when a process discovers that it cannot
continue (can happen automatically or through system call).
Note: Transitions 2 and 3 are caused by process scheduler,
which is a part of the OS.
Transition 2 occurs when the scheduler decides that running
process has had enough CPU time.
Transition 3 occurs when other processes have had their
share of the CPU and it is time for the first process to get the
CPU again.
Transition 4 occurs when the external event for which a
process was waiting (for example, arrival of input) happens.
March 5, 2024 Operating Systems 60
Process Management
Implementation of Processes
The OS maintains a process table or the Process
Control Block (PCB) to implement, the process
model with one entry per process.
It contains information about the process’ state, its
program counter, stack pointer, memory allocation,
status of its open files, its accounting etc.
This is necessary when the process is switched from
running to ready state so that it can be restarted later as
if it had never been stopped.
March 5, 2024 Operating Systems 61
Process Management
Implementation of Processes …
Process Control Block (PCB)
Pointer Process state
Process number (id)
Program counter
Registers
Memory limits
List of open files
March 5, 2024 Operating Systems 62
Process Management
Implementation of Processes …
1. Process State – State may be ready, blocked or running.
2. Program counter – Counter indicates the address of the next
instruction to be executed for this process.
3. CPU registers – Registers vary in number and type depending
on the computer architecture. They include accumulators, index
registers, stack pointers and general-purpose registers.
4. CPU scheduling information – includes a process priority,
pointer to scheduling queues and any other scheduling
parameters.
March 5, 2024 Operating Systems 63
Process Management
Implementation of Processes …
5. Memory management information – includes the
value of the base and limit registers, page tables or
segment tables.
6. Accounting information - includes the amount of CPU
and real time used, account numbers, time limits, process
numbers and so on.
7. I/O status information – includes the list of all I/O
devices allocated to this process, list of open files etc.
March 5, 2024 Operating Systems 64
Process Management
Threads
Traditionally, processes have a single thread of control.
In some modern O/S, support is provided for multiple
threads of control within a process.
These threads of control are called threads, or lightweight
processes.
For example in a file server process, the process receives
requests to read and write files and send back the requested
data or accepts updated data.
To improve performance, the server does caching, reading
from the cache and writing to the cache when possible.
March 5, 2024 Operating Systems 65
Process Management
Threads …
This situation lends itself to multi-threading.
When a request comes in, it is handed to a thread.
If that thread blocks part way through waiting for a disk
transfer, other threads can be able to run.
Model for single thread of control is not suitable since it is
imperative that file server threads access the same cache.
A separate thread table is necessary, because some of the
fields (for example, program counter, registers and state) in
the PCB will not be per process but per thread.
March 5, 2024 Operating Systems 66
Process Management
Threads …
a) Three processes each with one thread (original
process notion).
b) One process with three threads (multithreaded).
March 5, 2024 Operating Systems 67
Process Management
Threads …
Unlike multiple process, multiple thread do not have all of their
own resources, instead they share the resources of their parent
process.
March 5, 2024 Operating Systems 68
Process Management
Threads …
Threads can be implemented by the O/S or user space and
both vary in performance.
Switching threads is faster when thread management is
done in user space than when a kernel call is needed.
When thread management is done entirely in user space
and one thread blocks, the kernel blocks the entire process.
March 5, 2024 Operating Systems 69
Process Management
Implementing Threads
Threads implemented in user space
March 5, 2024 Operating Systems 70
Process Management
Implementing Threads
Advantages of user space threads
Can be implemented on any [sufficient] operating system
Thread switching is fast
Thread scheduling is fast
Disadvantages of user space threads
Use a cooperative approach to sharing the CPU
Blocking system calls are problematic since one blocked
thread will block all threads;
March 5, 2024 Operating Systems 71
Process Management
Implementing Threads
Threads implemented in kernel space
March 5, 2024 Operating Systems 72
Process Management
Implementing Threads
Threads implemented in kernel space
Advantages of kernel space threads
No runtime system in each process
Kernel can easily reschedule threads when they block
Disadvantages of kernel space threads
Thread switching is slower than user space threads
Thread scheduling is slower than user space threads
March 5, 2024 Operating Systems 73
Process Management
Threads …
Threads introduce a multitude of problems.
For instance, if a parent process has multiple threads,
should the child also have them?
If not, the process may not function properly, since all of
them may be essential.
However, if the child process gets as many threads as the
parent, what happens if a thread was blocked for a READ
call, say, from the keyboard.
Are the two processes now blocked on the keyboard?
When a line is typed, do both threads get a copy of it?
March 5, 2024 Operating Systems 74
Process Management
Threads …
Another problem is that threads may share data structures.
What happens if one thread closes a file while another one
is still reading from it?
Suppose that one thread notices that there is too little
memory and starts allocating more memory.
In the process of execution, another thread also notices
that there is little memory and also allocates memory.
Does the allocation happen once or twice?
These show that design of threading O/S requires much
thought and for backward compatibility should support
single threaded programs.
March 5, 2024 Operating Systems 75
The End
March 5, 2024 Operating Systems 76