17

STUDY MATERIAL

DEPARTMENT : SOFTWARE SYSTEMS

CLASS : II M.Sc

SUBJECT : OPERATING SYSTEMS

UNIT : II

Syllabus

Process Description and Control

Process states-process description-process control-processes and threads .

Concurrency: Mutul Exclusion

Principles of concurrency-mutual exclusion-software & hardware approaches

Semaphores –message passing.

Concurrency:deadlock and starvation

Principles of deadlock-deadlock prevention- deadlock detection-avoidance.

Process Description and Control

Process States:

* Execution of individual program is called as Process or Task.

* Principal Function of Process is to execute sequence of instructions in the Main memory

* It depends on the changing values of Register is called as Program Counter.

* Behavior of individual Program is called as characteristics by listing the sequence of instructions, executed for the process called as Traces of Process.

Two-state Process Model:

·  Process is of two states Running State and Not Running States.

·  If a Process is Created – Not Running State

·  If opportunity occurs to execute then process enters into Running State by the Dispatcher.

·  In the Queue, the processes, which are in Not Running States, are placed.

The Creation and Termination of Process:

Creation Of Process:

The Process will be created on the following occasion;

·  New Batch Job:

Present new batches of jobs

·  Interactive User Log on

When log on into the system – (LAN)

·  Created by Os to provide a Service.

Os will create the process when it provides a service to user.

·  Spawned by Existing Process.

A Process can create its own process.

That is Parent spawns Child Process.

Example: fork, exec commands in Unix will spawns child process and execute the process respectively.

fork exec

Termination Of Process:

·  Halt Instruction.

·  Os call.

·  Normal Completion.

·  Time limit.

·  Bound Violation.

·  Memory Unavailable.

·  Arithmetic Error (Divide by zero).

·  I/O failure (error occurs in I/O, to find a file or failure to read or write).

·  Time overrun (Wait longer than s specified for certain event to occur).

·  Invalid Instruction.

·  Privileged Instruction.

·  Data Misuse

·  Operator or OS instruction

·  Parent Termination.

·  Parent Request.

Five State Model:

Disadvantage in Two State Model:

In Two state model some process are in ready state and whereas others are blocked and waiting for an I/O Operation to complete, so in a single queue the process has to be wait for long time. So we are introduce more states.

They are:

New, Ready, Running, Blocked, Exit.

New:

Process initializations (Process Id, Process Tables)

Exit:

Successful Termination, abort of Process.

Process tables are stored temporarily until extraction of information is over that is accounting, billing, up gradation of Os.

Transition of states is:

Null-New;

New – Ready: Limit no. Of process.

Ready – Running : Ready to execute

Running-Exit : Successful Termination , abort of Process .

Running-Ready : Time out , Preemption

Running-Blocked : Waiting for I/O ( Event Wait)

Blocked –Ready : Event Occurs

Blocked – Exit : Aborts , Parent Terminates

Ready – Exit : Parent Terminates

For transition and Data structures r.t 3.5f , 3.6f

Disadvantage in Five State Model:

Memory is Wasted for the process which are in Blocked states.

CPU is ideal while all the process are in Blocked States.

Swapping :

Take the Process in Blocked (Waiting for I/O ( Event Wait)) out of main memory and put another process (ready to run ) into the Main Memory is called as

Swapping.

Process Suspension :

Swapping out a process from Blocked states – Secondary memory (Disk)

Is call as Process suspension and state is called as Suspend State.

Swapping in are of two choices ;

Newly Created , or Existing process ready to execute(previously suspend).

Additional Transitions are:

Blocked - Blocked Suspend : Swapping

Blocked – Suspend : Worst case (while all the process in ready, suspend are having lower priority when compared with process in former one ,and event for which process is in the former state is going to occur.

Blocked, Suspend - Ready, Suspend : Event Occurs

Ready, Suspend - Ready : Ready to execute.

Ready, Suspend – Running : Higher Priority when compared with ready state’s Process.

Ready - Ready, Suspend : If Enough memory is unavailable.

Running – Ready Suspend : Preemption ( Priority Concern)

For transition and Data structures r.t 3.7f

Uses:

Process not immediately available for execution

Process may or mayn’t waiting for an event

Process placed in suspend state by implicit , or by agent.

Process in suspend states can be invoked explicitly by agent.

Reasons for Suspension:

Swapping ,

Os reason – swap the process cause problem.

Interactive user request - In need of debugging

Timing - For marinating OS services.

Parent Process Request.

Process Description:

Operating System Control Structures:

Maintains tables of information about Process , resources etc;

Tables are:

Memory tables :

Allocation of Main memory to Process .

Allocation of Secondary memory to Process.

Protection attributes.

Any information needed to manage Virtual memory

I/O Tables:

OS to manage I/O devices and channels of Computer system.

To Know the current status if I/O devices.

Os has to know which process is currently allocated with which Process .

File Tables:

Existing Files,

Location of Files (Main or in Secondary Memory)

Attributes.

Current States.

Cross Reference needed between all the above tables.

Process Control Structures:

Os has to know Process Location

Attributes Of Process

Process Location:

Set of Programs,

Variables (Global or Local ),

Stack. Process Image

Control Information.

Process Control Structures:

Location , attributes

Process Location:

·  Continuous block of memory

·  Process is put into the secondary memory

·  Part of Process image resides in Main Memory is made use by OS.

·  During execution Process image is loaded into main memory.

In CTSS : Difficult to locate the traces(part) are reside in Main memory after swapping .

In Modern OS : Portion of Pages or Segments or Combination of both of a process are in Main memory.

Process table give location of a process by Process image.

User Data

User Program

System Stack : Parameters 0f address of subroutine etc ., LIFO

Process Control Block :

Process Identification :

Identifier of process , parent process , user identifier default Numeric

Process State Information:

User-Visible Register :Program area of execution ,8-32 register

RISC (100)

Control and states Register

Program counter,

Condition Codes :Carry, Zero, Equal, Sign, Overflow

Status Information : Interrupt Enable / Disable Flags

Stack Pointers:

Pointer to the starting address of stack

Process Control Information:

Scheduling and Status Information:

Process State : ready or not etc..

Priority ,Scheduling information (algorithm) , Event (Event for it is Waiting) .

Data Structuring : Type of DS maintained.

Inter process Communication : Messages , signals ,flags

Process Privileges : Privileges or priority in concern of instruction , address etc.,

Memory Management : Pointer for Page or Segment table

Resource Ownership and Utilization:

·  Owner of resource and information for maintaining OS services (Billing etc.,)

Example :VAX (r.t.3.10f)

Mode of Execution of Instruction

Kernel : Os program.

Supervisor : Os service.

Executive : file or record.

User : user mode of program.0

Shared Address

Space

Role of Process Control Block:

Manages scheduling , resource utilization , interrupt processing and performance

Monitoring and analysis .

Problems:

·  A bug in a single routine , such as interrupt handler , could damage process

Control blocks , which could destroy the system’s ability to manage the affected Process.

·  A design change in the structure or semantics of the process control block could affect a number of modules in the Operating system.

Process Control :

Modes of Execution:

Two Modes:

Higher Privileged Mode. (accessing of certain regions of memory)

Less Privileged Mode. (user mode)

More Privileged Mode(System Mode, Control mode , Kernel Mode)

Kernel Functions are;

Process Management

Process creation and Management

Process scheduling and Dispatching.

Process Switching

Process Synchronization

Inter Process Communication

Memory Management

Allocation of address space to processes

Swapping

Page and Segment Management

I/O Management

Buffer Management.

Allocation of I/O channels and devices to Processes.

Support Functions:

Interrupt Handling

Accounting

Monitoring

PSW :

Indicates the mode of execution by its bit.

When user makes a operating system service , the mode is set to the kernel mode .typically , this is done by executing an instruction that changes the mode. This is done by Change Mode(CHM). When the user makes a system service call or when an interrupt transfers control to a system routine , the routine executes CHM to enter more privileged mode and executes it again to enter a less privileged mode before returning control to the user process. If a user program attempts to execute a CHM , it will simply result in a call to the Operating System , which will return an error unless the mode change is to be allowed.

Creation of Process:

·  Assign a unique Process identifier to the new process.

·  New Entry is added to the Primary Process table , which contain one entry per process.

·  Allocate space for the process.

·  Process control block must be initialized .

·  Process Id contains the ID of this process plus other appropriate Ids (Parent Process)

·  Program counter and system stack is initialized.

·  Process Control Information is initialized.

·  Appropriate linkages must be set.

·  Other data structures to be created or expanded.

Process Switching:

i)  Which event triggers a Process switch

ii)  Decisions to be made whether Process switching or Context switching is done

iii)  Operating System do.

Chang Of State occurs

When to switch the Process:

Interrupt :

External Disturbance.

Asynchronous External event.

Types Of interrupt:

Clock interrupt ,

I/o Interrupt (Preempts),

Memory fault.

Trap :

Internal Disturbances.

Handling of an error of exceptional condition .(fatal error)

Supervisor Call:

Explicit request .

Call to an Operating System Function.

Context Switching:

·  Saves the context of the current program being executed.

·  Sets the Program counter to the starting address of an interrupt handler program.

If the interrupt occurs ;

·  Reset the flag or indicator .

·  Send the Acknowledgement

·  Housekeeping Jobs – Check for error condition

·  If interrupt is due to clock interrupt then dispatcher moves another process into the Processor.

·  Process Control block to store the information(status , priority information)

Change of Process State:

Context Switch : Context is changed and switching occurs without the change of state.

Steps involved in the Complete Process Switching :

ü  Save the context of a Process

ü  Update the Process Control Block (Change in states information has to be updated)

ü  Move the Process control block to the appropriate Queue.

ü  Select another Process for execution.

ü  Update the Process Control block of the Process selected.

ü  Update Memory-Management data structures .

ü  Restore the context of the Processor to that which existed ate the time the selected Process was last out of the running state by loading in the previous values of program counter and other registers.

Execution Of the Operating System:

·  Whether Os is a Process

·  Os frequently releases control and must depend on the Processor to allow it to regain control.

Non Process Kernel:

Ø  Kernel is executed separately from all other process.

Ø  If interrupt occurs for the process by the Supervisor Call , Context switching occurs.

Ø  Protection is given to the Kernel by User and System mode.

Execution within the user Process:

Ø  Minicomputers and Microcomputers.

Ø  Frequently used function is kept in each user process .

Ø  ‘N’ copies of the Frequently used function are kept inside the user process.

Ø  User program within a process is executed in a User Mode.

Ø  Kernel Program is executed in Kernel Mode

Ø  If trap or interrupt or supervisor call occurs control go to kernel and Kernel Process the interrupt and then sends its control to the user Program. Hence here context switching occurs which avoids process switching

Process Based Operating System:

Separate process

Evolution of modular operating system

Micro kernels

Ø  Main components or program of OS are put into the Kernel whereas other components of os are put outside the kernel

Ø  Size of kernel capacity will be reduced .

Ø  Outside components are communicate with one another in the basis of peer to peer basis while kernel is acts as barrier between all the components which are kept outside of the kernel and validates the communication.

Process and Threads:

ü  Unit of process executed separately are called as thread .

ü  Unit of dispatching is called as thread.(reading a file , writing into buffer , printing)

ü  Unit of resource ownership is called as Process or task (Print out)

Task:

Virtual address space that holds the task image

Protected access to resource

Thread:

v  Thread Execution state

v  Program counter for each thread

v  An execution stack

v  Static storage global variable for each thread

v  Access to memory or resources to the task where it resides.

v  Share of resources within the threads.

Advantages Of Thread:

ü  Less time for creation of thread

ü  Less time for execution of thread

ü  Less time for switching from thread to thread

ü  More efficient because similar functions are organized as a single thread.

Example:

File Server , Communication Processing , Transaction Processing Monitor

Four examples of uses in thread: