Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 42

Overview of Operating System

Operating System

Dr. Jayashri Bagade


Jayashree.bagade@viit.ac.in
Department of Information Technology

BRACT’S, Vishwakarma Institute of Information Technology, Pune-48


(An Autonomous Institute affiliated to Savitribai Phule Pune University)
(NBA and NAAC accredited, ISO 9001:2015 certified)
Objective/s of this session

1. To understand the concept of process and thread management.

Learning Outcome/Course Outcome

1. Understand & implement the concept of a process and thread.

Department of Information Technology, VIIT , Pune-48


Content
Part –I
 Process: Concept of a Process, Process States, Process Description, Process
Control (Process creation, Waiting for the process/processes, Loading programs
into processes and Process Termination)
Part-II
 Execution of the Operating System. Threads: Processes and Threads, Concept of
Multithreading, Types of Threads, Thread programming using Pthreads.
Part-III
 Scheduling: Types of Scheduling, Scheduling Algorithms, and Thread
Scheduling.

Department of Information Technology, VIIT, Pune-48


P1 P2 Pn
Virtual
Memory

Computer
Resources
Main
Processor I/O I/O I/O
Memory

Figure 3.10 Processes and Resources (resource allocation at one snapshot in time)

Courtesy : Operating System Internals and Design Principles by William Stallings

Department of Information Technology, VIIT, Pune-48


Process
Image
Memory Tables
Process
Memory 1

Devices I/O Tables

Files

Processes File Tables

Primary Process Table

Process 1

Process 2
Process
Process 3 Image
Process
n

Process n

Figure 3.11 General Structure of Operating System Control Tables

Courtesy : Operating System Internals and Design Principles by William Stallings

Department of Information Technology, VIIT, Pune-48


Memory Tables

• Used to keep track of both


main (real) and secondary
(virtual) memory Must include:

• Processes are maintained on


secondary memory using some allocation of main memory to processes
sort of virtual memory or
allocation of secondary memory to processes
simple swapping mechanism
protection attributes of blocks of main or virtual
memory

information needed to manage virtual memory

Department of Information Technology, VIIT, Pune-48


I/O Tables

• Used by the OS to manage the


I/O devices and channels of the
computer system
• At any given time, an I/O
If an I/O operation is in progress, the OS needs to
device may be available or know:
assigned to a particular process the status of the I/O operation
the location in main memory being used as
the source or destination of the I/O transfer

Department of Information Technology, VIIT, Pune-48


File Tables
These tables provide information about:


existence of files

location on secondary memory

current status
• Information

may be maintained
other attributes and used by a file management
system
• in which case the OS has little or no knowledge of files

• In other operating systems, much of the detail of file management is managed by the OS
itself

Department of Information Technology, VIIT, Pune-48


Process Tables
• Must be maintained to manage processes
• There must be some reference to memory, I/O, and files,
directly or indirectly
• The tables themselves must be accessible by the OS and
therefore are subject to memory management

Department of Information Technology, VIIT, Pune-48


Process Control Structures

To manage and ●
where the process is located
control a process ●
the attributes of the process
the OS must that are necessary for its
management
know:

Department of Information Technology, VIIT, Pune-48


Process Control Structures

Process Location Process Attributes

• A process must include a program or • Each process has associated with it


set of programs to be executed a number of attributes that are
• A process will consist of at least used by the OS for process control
sufficient memory to hold the • The collection of program, data,
programs and data of that process stack, and attributes is referred to
• The execution of a program typically as the process image
involves a stack that is used to keep • Process image location will depend
track of procedure calls and on the memory management
parameter passing between scheme being used
procedures

Department of Information Technology, VIIT, Pune-48


Typical Elements of a Process Image

Department of Information Technology, VIIT, Pune-48


Typical
Elements of a
Process
Control
Block

Department of Information Technology, VIIT, Pune-48


Typical
Elements of a
Process Control
Block

Department of Information Technology, VIIT, Pune-48


Process Identification
• Each process is assigned a • Memory tables may be organized to
provide a map of main memory with
unique numeric identifier an indication of which process is
• otherwise there must be a assigned to each region
mapping that allows the OS to • similar references will appear in I/O
locate the appropriate tables and file tables
based on the process identifier • When processes communicate with
• Many of the tables controlled one another, the process identifier
informs the OS of the destination of a
by the OS may use process particular communication
identifiers to cross-reference • When processes are allowed to
process tables create other processes, identifiers
indicate the parent and descendents
of each process

Department of Information Technology, VIIT, Pune-48


Processor State Information

Consists Progra
of the ●
user-visible ●
contains condition codes
content registers m plus other status
information
s of ●
control and status ●
EFLAGS register is an
process example of a PSW used by
status registers
or ●
stack pointers
word any OS running on an x86
processor
registers (PSW)
Department of Information Technology, VIIT, Pune-48
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
I
V V
I A V R N O O D I T S Z A P C
0 0 0 0 0 0 0 0 0 0 I I 0 0 0 1
D C M F T P F F F F F F F F F
P F
L

X ID = Identification flag C DF = Direction flag


X VIP = Virtual interrupt pending X IF = Interrupt enable flag
X VIF = Virtual interrupt flag X TF = Trap flag
X AC = Alignment check S SF = Sign flag
X VM = Virtual 8086 mode S ZF = Zero flag
X RF = Resume flag S AF = Auxiliary car ry flag
X NT = Nested task flag S PF = Parity flag
X IOPL = I/O privileg e level S CF = Carry flag
S OF = Overflow flag

S Indicates a Status Flag


C Indicates a Control Flag
X Indicates a System Flag
Shaded bits are reserved

Figure 3.12 x86 EFLAGS Register

Courtesy : Operating System Internals and Design Principles by William Stallings

Department of Information Technology, VIIT, Pune-48


Pentium

EFLAGS

Register

Bits

Department of Information Technology, VIIT, Pune-48


Process Control Information

• The additional information needed by the OS to control and


coordinate the various active processes

Department of Information Technology, VIIT, Pune-48


Process Process Process
Identification Identification Identification
Process
Processor State Processor State Processor State Control
Information Information Information Block
Process Control Process Control Process Control
Information Information Information

User Stack User Stack User Stack

Private User Private User Private User


Address Space Address Space Address Space
(Programs, Data) (Programs, Data) (Programs, Data)

Shared Address Shared Address Shared Address


Space Space Space

Process 1 Process 2 Process n

Figure 3.13 User Processes in Virtual Memory

Courtesy : Operating System Internals and Design Principles by William Stallings

Department of Information Technology, VIIT, Pune-48


Process
Control Block
Running

Ready

Blocked

Figure 3.14 Process List Structures

Department of Information Technology, VIIT, Pune-48


Role of the Process Control Block

• The most important data structure in an OS


• contains all of the information about a process that is needed by the OS
• blocks are read and/or modified by virtually every module in the OS
• defines the state of the OS
• Difficulty is not access, but protection
• a bug in a single routine could damage process control blocks, which could
destroy the system’s ability to manage the affected processes
• a design change in the structure or semantics of the process control block
could affect a number of modules in the OS

Department of Information Technology, VIIT, Pune-48


Modes of Execution

User Mode System Mode

• less-privileged mode • more-privileged mode


• user programs typically • also referred to as control
execute in this mode mode or kernel mode
• kernel of the operating
system

Department of Information Technology, VIIT, Pune-48


Typical
Functions
of an
Operating
System
Kernel

Department of Information Technology, VIIT, Pune-48


Process Creation
• Once the OS decides to create a new process it:
initializes
sets thea unique
assigns the
allocates space
appropriate
process
process control
identifier
for
to the
the
block
linkages process
new process

cr
ea
tes
or
ex
pa
nd
s
ot
he
r
da
ta
str
uc
tur
es

Department of Information Technology, VIIT, Pune-48


Mechanisms for Interrupting the Execution of a Process

Department of Information Technology, VIIT, Pune-48


System Interrupts

Interrupt Trap
• Due to some sort of event that is • An error or exception condition
external to and independent of generated within the currently
the currently running process running process
• clock interrupt • OS determines if the condition
• I/O interrupt is fatal
• memory fault • moved to the Exit state and
• Time slice a process switch occurs
• the maximum amount of time
• action will depend on the
that a process can execute
before being interrupted nature of the error
Department of Information Technology, VIIT, Pune-48
Mode Switching
If an interrupt is pending the processor:
nterrupts are pending the processor:

sets the program counter to the starting address of an interrupt handler program

proceeds to the fetch stage and fetches the next


instruction of the current program in the current process switches from user mode to kernel mode so that the interrupt processing code may include privileged
instructions

Department of Information Technology, VIIT, Pune-48


Change of Process State
• The steps in a full update the process con
save the context of the
process switch block of the process
are: processor currently in the Runnin
state
If the currently running process is to be moved to another state (Ready,
Blocked, etc.), then the OS must make substantial changes in its
environment

move the process control


block of this process to the
appropriate queue

update the process con


select another process for
Department of Information Technology, VIIT, Pune-48 block of the process
P1 P2 Pn

Execution
Kernel

(a) Separate kernel

of the P1 P2 Pn

Operating System
OS OS OS
Func- Func- Func-
tions tions tions

Process Switching Functions

(b) OS functions execute within user processes

P1 P2 Pn OS1 OSk

Process Switching Functions

(c) OS functions execute as separate processes

Figure 3.15 Relationship Between Operating


System and User Processes

Courtesy : Operating System Internals and Design Principles by William Stallings

Department of Information Technology, VIIT, Pune-48


Process

Execution Within User


Identification

Processor State Process Control


Information Block

Processes Process Control


Information

User Stack

Private User
Address Space
(Programs, Data)

Kernel Stack

Shared Address
Space

Figure 3.16 Process Image: Operating System


Executes Within User Space

Courtesy : Operating System Internals and Design Principles by William Stallings

Department of Information Technology, VIIT, Pune-48


Unix SVR4
• Uses the model where most of the OS executes within the
environment of a user process
• System processes run in kernel mode
• executes operating system code to perform administrative and housekeeping
functions
• User Processes
• operate in user mode to execute user programs and utilities
• operate in kernel mode to execute instructions that belong to the kernel
• enter kernel mode by issuing a system call, when an exception is generated, or
when an interrupt occurs

Department of Information Technology, VIIT, Pune-48


UNIX Process States

Department of Information Technology, VIIT, Pune-48


fork

Created
Preempted

return enough not enough memory


to user memory (swapping system only)

User
Running preempt
swap out
return Ready to Run Ready to Run
reschedule
In Memory Swapped
process swap in
system call,
interrupt Kernel
Running

sleep wakeup wakeup


interrupt,
interrupt return exit

Asleep in swap out Sleep,


Zombie
Memory Swapped

Figure 3.17 UNIX Process State Transition Diagram

Department of Information Technology, VIIT, Pune-48


UNIX
Process
Image

Department of Information Technology, VIIT, Pune-48


UNIX Process
Table Entry

Department of Information Technology, VIIT, Pune-48


UNIX U Area

Department of Information Technology, VIIT, Pune-48


Process Creation

1 ●
Allocate a slot in the process table for the new process
• Process creation is
by means of the 2 ●
Assign a unique process ID to the child process
kernel system call,
fork( ) 3 ●
Make a copy of the process image of the parent, with the exception of any shared memory

• This causes the


OS, in Kernel 4 Increments counters for any files owned by the parent, to reflect that an additional process now also owns those files

Mode, to:
5 ●
Assigns 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

Department of Information Technology, VIIT, Pune-48


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
• transfer control to the child process
• transfer control to another process

Department of Information Technology, VIIT, Pune-48


Summary
• What is a process? • Process control
• Background • Modes of execution
• Processes and process control blocks • Process creation
• Process switching
• Process states
• Two-state process model • Execution of the operating system
• Nonprocess kernel
• Creation and termination
• Execution within user processes
• Five-state model
• Process-based operating system
• Suspended processes
• UNIX SVR4 process management
• Process description • Process states
• Operating system control structures • Process description
• Process control structures • Process control

Department of Information Technology, VIIT, Pune-48


To be discussed next time
Part –I
 Process: Concept of a Process, Process States, Process
Description, Process Control (Process creation, Waiting for
the process/processes, Loading programs into processes and
Process Termination) Execution of the Operating System.
Part-II
Threads: Processes and Threads, Concept of Multithreading,
Types of Threads, Thread programming using Pthreads.
Part-III
 Scheduling: Types of Scheduling, Scheduling Algorithms,
and Thread Scheduling.
Department of Information Technology, VIIT, Pune-48
Thank You

Department of Information Technology, VIIT, Pune-48

You might also like