process and its related concept with problems

37
OPERATING SYSTEM JIT Barabanki Mr Satyendra Mohan Srivastava

Upload: satyendra-mohan

Post on 08-Feb-2017

35 views

Category:

Engineering


4 download

TRANSCRIPT

Page 1: Process and its related concept with problems

OPERATING SYSTEM

JIT BarabankiMr Satyendra Mohan Srivastava

Page 2: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 2

Process A process is a program in execution

A process can also be defined as the unit of work in a time sharing system

A system consist of bunch or collection of processes

Operating system processes execute system codes and various user processes executing various user codes

The various processes can execute concurrently via CPU multiplexing mechanism

The CPU switches between various processes which make computer system more productive

Page 3: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 3

Process (conti..) Most of the text books of operating system uses job and processes interchangeably

Program can be passive entity stored on disk (executable file) but process is active entity

Program becomes process when executable file loaded into memory

A program can be divided into several processes

A process can be larger than program code (text selection)

Process can also includes various activities which is represented by the value of the program counter and contents of processors registers

A process includes the process stack (temporary data) and a data section (global variables)

Page 4: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 4

When the process executes, it may changes its state

new: The process is created in this state

running: The various instructions are being executed

waiting: The various process are waiting for some event to occur

ready: The various process are waiting to be assigned to a processor

terminated: The execution of process has finished

Process State

Page 5: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 5

Diagrammatic Representation of Process State

Interrupt

New Terminated

Ready Running

Waiting

Scheduler dispatch

Admitted Exit

I/O or Event waitI/O or Event Completion

Page 6: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 6

Process Control Block (PCB)

PointerProcess State

Process Number

Program Counters

Registers

Memory Limits

List of open files

. . .

Each process in the operating system is represented by a PCB

PCB is also known as a task control block

PCB contains pieces of information associated with a specific process. The various block along with the description are listed below:

Process state : The states like new, ready, running, waiting, terminated and so on PCB

Page 7: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 7

Process Control Block (PCB)

PointerProcess State

Process Number

Program Counters

Registers

Memory Limits

List of open files

. . .

Program Counter : It indicates the next instruction address which is to be executed

Registers : It include accumulators, stack pointers, index registers, general purpose registers and any conditional code information

PCB

Page 8: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 8

CPU Switching from Process to Process

Process P(i) Operating System Process P (i+1)

Interrupt or system call

Save state into PCB

Save state into PCB

Save state into PCB

Save state into PCB

Executing

Executing

Executing

idle

idle

idle Interrupt or system call

Page 9: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 9

Threads A process is a program that performs a single thread of execution

A single thread of instructions allows the process to perform one task at one time

Various modern operating system have extended the basic process concept to have multiple thread of execution

The process can perform more than one task at a time

A thread is also known as light weight process

A thread can be define as primary unit of CPU utilization

Page 10: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 10

Threads

Advantages:

Resource sharing

Responsiveness

Economy

Utilization of multiprocessor architecture

Page 11: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 11

Process Scheduling The objective of Multiprogramming is to maximize the number of process

running at all time. This leads to maximize CPU utilization.

The objective of Time-sharing is to maximize the CPU switching among the process so that users can interact with each process or program while it is running

Only one process is running on uniprocessor system all the time

If more than one processes exit, the rest process may wait until CPU is free or scheduled on the CPU

The various processes in the system are put into job queue

The job queue contain all the processes in the system

Page 12: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 12

In Main Memory, the processes are ready and waiting to execute. Such state in the list are known as the ready queue

The processes in the list are stored as a linked list format

A ready queue header in the list contain the pointer which points to the first and the final Process Control block in the list

The operating system may also contain other queues

The various processes are going to provide the CPU then processes may execute, gets interrupted and wait for a particular event (I/O request)

The various request of processes can be depicted on the tape drive or on the disk

Process Scheduling

Page 13: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 13

Process Scheduling On the disk, system may be busy with the I/O request of some other

processes hence processes on the disk have to wait for its number to acquire CPU

The waiting processes of the list for a particular I/O device are known as device queue

Each individual device has its own device queue

The diagrammatic representation of device which represent process scheduling is known as queueing diagram

Two type of Queue are present in the operating system The ready queue A set of device queue

Page 14: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 14

Process Scheduling

When the CPU is assigned to the process and process start its execution, following are the possibilities:

The process may issue an I/O request and placed on an I/O queue

The process may create new sub-processes and wait for its completion

Due to interrupt, the process may removed from CPU and put on the ready queue

Page 15: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 15

Process Scheduling

Ready Queue CPU

I/O I/O queue I/O request

Time slice expired

Child executes

Interrupt occurs

Fork a child

Wait for an interrupt

Page 16: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 16

Schedulers The operating system select processes from various scheduling queue

The selection of process is purely dependent on appropriate scheduler

The processes are spooled to a disk(mass storage device) for some later execution

CPU scheduler or Short-term scheduler Select next process to be executed and provide the CPU Sometimes, the only available scheduler in a particular system CPU scheduler is invoked so frequently that it is considered as the fast

one

Page 17: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 17

Schedulers Job scheduler or Long-term scheduler

It select the various processes on the ready queue Job scheduler is comparatively less frequently invoked than CPU

scheduler It controls the degree of multiprogramming

Processes can be

CPU-bound process: It spends large time doing computations; few long CPU bursts

I/O-bound process: It spends large time doing I/O than computations, few short CPU bursts

Page 18: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 18

Schedulers

Partially executed swapped-out processes

Ready queue CPU

I/O I/O waiting queues

swap in swap out

In Queuing diagram, addition of Medium Term Scheduler

Page 19: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 19

Context Switch Context Switching is the mechanism which allows switching of processes or from

one state to another state

While CPU switches from one process to another process, the system should save the state of old process and load the new state (saved state) for the new process

The Context of a process can be represented via the PCB block diagram

The system perform no useful task while switching from one process to another. Such state is known as Context-switch time overhead

the context switch is directly proportional to the complex OS and the PCB

Multiple contexts can be loaded at once when multiple sets of registers per CPU will be provided by the hardware

Page 20: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 20

Operations on ProcessesThe processes in the system may execute concurrently. They may create and delete process dynamically. It provide mechanisms for:

Process creation

Process termination

Process creation

A process can create new processes with the help of create process system

The various creating process is known as a Parent process

Page 21: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 21

Operations on Processes Process creation

The new created process is known as the Children process

The newly created process may create various sub processes forming a tree of processes

A process need certain resource to complete its task

Such resources are CPU time, files, memory and I/O devices

The parent also partition its resource to its children

Restricting a child process leads to the restriction of process overloading in the system

Page 22: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 22

Operations on Processes Process creation

The information or data to the child process is passed via parent process

Creation of process leads to two possibilities, Such as

The child along with the parent continue to execute concurrently The parent with the child may wait to complete its execution or

its termination

Creation of process along with the address space leads to two possibilities

Duplication of parent process leads to child process

Page 23: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 23

Producer - Consumer Problem A producer process produces data or information that is ultimately

consumed by consumer process

For concurrent execution of various process, a buffer is required

A producer process can produce information and consumer process consume the information produced by consumer process

A synchronization between producer process and consumer process is required to overcome various unwanted situation like,

Consumer may try to consume the information which yet to be produced. This leads to waiting of consumer process

Page 24: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 24

Producer - Consumer Problem

Producer may try to produce the information when buffer is full. This leads to waiting of producer process to consume some information by consumer process

The buffer can be provided by the operating system or the application program

The buffer can be categorized into two types:

The Bounded-Buffer Assumes unbounded buffer size

The Unbounded-Buffer Assumes a fixed buffer size

Page 25: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 25

Critical Section Problem

A system consisting of processes has a code segment called a critical section

At a particular instant of time, Only one process is allowed to perform its execution in the critical section

No two processes at any instant of time are allowed in the critical section

The execution of processes in the Critical Section must be mutually exclusive

Each process may request permission to enter into critical section

Critical Section has entry level and exit level section

Page 26: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 26

Critical Section Problem A solution to Critical Section problem may satisfy the three requirements:

Mutual Exclusion Progress Bounded Waiting

Mutual Exclusion: When a process reside in the critical section then no two process is allowed in the critical section

Progress: The non executing processes in the remainder section can participate in the decision regarding the next process entry in the critical section

Boundary Waiting: There is a maximum limit of request to be made by a process to enter in the critical section

Page 27: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 27

The Dining Philosophers Problem

Rice

Page 28: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 28

The Dining Philosophers Problem The five Philosophers are sitting on five chairs sharing a common table

In the center of the table, some rice in a bowl is placed with the five chopsticks

The philosophers may exist in either thinking or eating phase

In thinking phase, a philosopher doesn’t interact with her colleagues

When a philosopher is hungry then the philosopher tries to pick up the two chopsticks that are closer to them

A philosopher can pick only one chopsticks at a time

A philosopher is in eating phase when he pick two chopsticks

Page 29: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 29

The Dining Philosophers Problem After eating, the Philosopher releases two chopsticks

A philosopher is in eating phase when he pick two chopsticks

Page 30: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 30

Deadlock A deadlock is a situation in which waiting process is requesting for the

resources which is hold by another process thus resulting in a situation known as a Deadlock

A resource can be memory space, files, CPU cycles and I/O devices

A resource may be granted to a process when process request for it

In any situation, a requesting resource can be exceed over the number of available resources

In the normal situation, a resource can be granted via following sequence: Requesting for resource Use of resource Release of resource

Page 31: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 31

DeadlockNote: Release and request for resources are system calls

A resource can be:

logical resource Physical resource

Logical Resource Semaphores Files

Physical Resource Printer Memory Space CPU cycle Tape drives

Page 32: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 32

Deadlock Characterization

Necessary Conditions: A deadlock may occur if following four conditions satisfied simultaneously in a system

Mutual exclusion

Hold and wait

No preemption

Circular wait

Page 33: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 33

Resource Allocation Graph

A directed graph representation of graph is known as resource allocation graph

In resource allocation graph, Following are the representation:

Process is represented by . in the graph

Process to resource directed allow head is known as a requesting edge

Resource to process directed arrow head is known as assignment edge

A sample resource allocation graph is represented on next slide

Page 34: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 34

A sample Resource Allocation GraphR1 R3

P1 P2 P3 P4

R2 R4

Page 35: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 35

Deadlock PreventionDeadlock is the state, we can avoid this state of processes by ensuring that that atleast one condition can’t hold so by elaborating the necessary four condition with this approach. The four condition are

Mutual exclusion

Hold and wait

No preemption

Circular wait

Page 36: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 36

Recovery from Deadlock Process termination

Deadlock elimination via sequential elimination of process

Elimination of all deadlocked processes

Resource preemption

Rollback Selecting a victim Starvation

Page 37: Process and its related concept with problems

05/01/2023 Mr Satyendra Mohan Srivastava, JIT Barabanki 37