You are on page 1of 21

OPERATING SYSTEMS (CS C372 & IS C362)

LECTURE 6: PROCESS

Process Concept

An operating system executes a variety of programs:


Batch system jobs Time-shared systems user programs or tasks

Process

A program in execution Program is passive entity and Process is active entity process execution must progress in sequential fashion
Biju K Raveendran@BITS Pilani. 2

9 August 2011

Process concept

In multi programming / multi tasking environment number of processes can reside in the system At any instance of time processes can be in different state such as Ready, Blocked, Running etc. and processes move from one state to another state depending upon certain conditions. Processes use available system resources OS is responsible for managing all the processes in the system

9 August 2011

Biju K Raveendran@BITS Pilani.

Process Concept

Program has just code NOT Live entity Process with data, work-space

Stack Heap File descriptors Other primitives ipc, memory, Register content Program counter General purpose registers

Open files

Execution snapshots

9 August 2011

Biju K Raveendran@BITS Pilani.

Process in Memory

9 August 2011

Biju K Raveendran@BITS Pilani.

Linux process run-time memory

9 August 2011

Biju K Raveendran@BITS Pilani.


Fig courtesy: Computer Systems: a programmers perspective

Example Execution
Address

Main Memory Dispatcher

0 100

Program Counter
8000

5000

Process A
8000

Process B
12000

Process C

Figure 3.2 Snapshot of Example Execution (Figure 3.4) at Instruction Cycle 13

9 August 2011

Biju K Raveendran@BITS Pilani.

9 August 2011

Biju K Raveendran@BITS Pilani.

A simple scenario: Two-State Process Model


Process may be in one of two states


Running Not-running

9 August 2011

Biju K Raveendran@BITS Pilani.

Not-Running Process in a Queue

What processes are in queue?


Process timed out Process gone for I/O
Both are 2 different scenarios

9 August 2011

Biju K Raveendran@BITS Pilani.

10

Process

Not-running

Ready to run given chance Blocked/waiting for event

Why not three states then?

9 August 2011

Biju K Raveendran@BITS Pilani.

11

Three state model


Admit Ready Time out Dispatch Release Running

Blocked

9 August 2011

Biju K Raveendran@BITS Pilani.

12

Three state model: Queuing Diagram

9 August 2011

Biju K Raveendran@BITS Pilani.

13

Multiple Blocked Queues


Ready Queue Admit Dispatch
Processor

Release

Timeout

Event 1 Queue Event 1 Occurs Event 2 Queue Event 2 Occurs

Event 1 Wait

Event 2 Wait

Event n Queue Event n Occurs Event n Wait

(b) Multiple blocked queues


9 August 2011 Biju K Raveendran@BITS Pilani. 14

Four state model


Need to create process


Process control block Verify availability of resources


Admit Dispatch Release Ready Time out Running

New

Blocked

9 August 2011

Biju K Raveendran@BITS Pilani.

15

Why do we need New state


New job submission


OS creates data structure for keeping track of the process context OS tries to load the process. System have enough memory to hold the process System have enough resources to execute processes in efficient manner

Load a new process only if


To efficiently execute processes, system may put a maximum limit on processes in ready queue
Biju K Raveendran@BITS Pilani. 16

9 August 2011

Five State Model


As a process executes, it changes state New


The process is being created Instructions are being executed The process is waiting for some event to occur The process is waiting to be assigned to a processor The process has finished execution
Biju K Raveendran@BITS Pilani. 17

Running

Waiting

Ready

Terminated

9 August 2011

Diagram of Process State

9 August 2011

Biju K Raveendran@BITS Pilani.

18

Process Scheduling Queues


Job queue set of all processes in the system Ready queue set of all processes residing in main memory, ready and waiting to execute Device queues set of processes waiting for an I/O device Processes migrate among the various queues

9 August 2011

Biju K Raveendran@BITS Pilani.

19

Ready Queue And Various I/O Device Queues

9 August 2011

Biju K Raveendran@BITS Pilani.

20

Representation of Process Scheduling

9 August 2011

Biju K Raveendran@BITS Pilani.

21

You might also like