23565104 process-management(2)

31
Module 2

description

 

Transcript of 23565104 process-management(2)

Page 1: 23565104 process-management(2)

Module 2

Page 2: 23565104 process-management(2)

OS RESPONSIBILITIES FOR PROCESS MGMT.

Creating and deleting of process Scheduling of a process (suspending and resuming

the execution of process) Process synchronization Process communication Deadlock handling

Page 3: 23565104 process-management(2)

WHAT IS A PROCESS? Process

– Program in execution needing resources (such as CPU time, memory, files and I/O devices) to accomplish its tasks.

- Executing set of machine instructions- Execution of a process must progress in a sequential fashion; at

most one instruction is executed on behalf of the process.

Page 4: 23565104 process-management(2)

COMPONENTS OF A PROCESS Code Data Resources Status Threads

Page 5: 23565104 process-management(2)

CLASSIFICATION OF OS ACCORDING TO THE TYPES OF SYSTEM: Single-process single-threaded – only one

process can execute at a time. Once a process is allocated to the CPU, that process runs to completion before any other process can execute.

Example: DOS

Page 6: 23565104 process-management(2)

CLASSIFICATION OF OS ACCORDING TO THE TYPES OF SYSTEM:

Multi-process single threaded – a single entity (the process), is the object upon which both resource allocation and CPU scheduling are performed.

Example: UNIX

Page 7: 23565104 process-management(2)

CLASSIFICATION OF OS ACCORDING TO THE TYPES OF SYSTEM: Multi-process multi-threaded – resources are

allocated to the processes but CPU scheduling can be in terms of thread.

Example: Windows, Mach, Solaris

Page 8: 23565104 process-management(2)

IS PROCESS THE SAME AS PROGRAM? No, it is both more and less

More – a program is just part of a process context.

Less – a program may invoke several processes

Page 9: 23565104 process-management(2)

UNIPROGRAMMING & MULTIPROGRAMMING

Uniprogramming allows execution of only one process at a time (e.g.

personal computer)

Multiprogramming allows more than one process (e.g. concurrent execution

of many processes)

Page 10: 23565104 process-management(2)

HOW CAN SEVERAL PROCESSES SHARE ONE CPU?

OS takes care of this by making sure that:

Each process gets a chance to run (fair scheduling)

They do not modify each other’s state(protection)

Page 11: 23565104 process-management(2)

OS EXECUTION

An OS executes a variety of programs: Batch systems Time-shared systems

Page 12: 23565104 process-management(2)

A PROCESS INCLUDES:

Program counter and contents of processor registers.

Process stack (contains temporary data such as subroutine parameters, return addresses, variables)

Data section (contains global variables) Heap

Memory that is dynamically allocated during run time.

Page 13: 23565104 process-management(2)

SIX (6) PROCESS STATES:

New Process is being created but not yet included in the pool

of executable processes (resource acquisition) Ready

Waiting to be assigned to the processor Running (or active)

Process that is currently being executed

Page 14: 23565104 process-management(2)

SIX (6) PROCESS STATES: (CONT)

Waiting (or blocked) Waiting for some event to occur (I/O completion)

Stopped Special case of blocked where the operator/user

suspends the process. Terminated (or exiting)

Process has finished execution. A process is about to be removed from the pool of executable processes.

Page 15: 23565104 process-management(2)

DIAGRAM OF PROCESS STATE

NewNewReadyReady ActiveActive ExitingExiting

StoppedStopped

BlockedBlocked

create

resume time-out

dispatch

suspendkill

kill

exit

error

Event occurs or resource available

State transition_____ internal_ _ _ _external

Page 16: 23565104 process-management(2)

PROCESS CONTROL BLOCK (PCB) Each process is represented in the OS by a PCB. It is where collection of process information are kept

and accessed.

Sometimes called the Task Control Block (TCB)

Page 17: 23565104 process-management(2)

PCB INFORMATION:

Process state Program counter (PC) CPU Registers CPU Scheduling information Memory-Management Information Accounting information I/O status information

Page 18: 23565104 process-management(2)

PROCESS CONTROL BLOCK

Page 19: 23565104 process-management(2)

Operations on Processes• Create a process• Destroy a process• Suspend a process• Resume a process• Change the priority of a process• Block a process• Wake up a process• Dispatch a process• Enable interprocess communication

Page 20: 23565104 process-management(2)

CONTEXT SWITCH When a CPU switches to another process, the system

must save the state of the old process and load the saved state of the new process

Context-switch time is overhead; the system does no useful work during switching.

Page 21: 23565104 process-management(2)

CONTEXT SWITCH

Page 22: 23565104 process-management(2)

PROCESS SCHEDULING:

Objective of multiprogramming: have some user process running at all times

OS keeps the CPU busy with productive work by dynamically selecting (scheduling) the next user process to become active.

Page 23: 23565104 process-management(2)

SCHEDULING QUEUES Job queue

Set of all processes that enter the system Ready queue (linked-list)

Set of all processes residing in main memory, ready and waiting to execute.

Device queues Set of processes waiting for an I/O device, each device

has a device queue.

Page 24: 23565104 process-management(2)

QUEUING DIAGRAM:

Page 25: 23565104 process-management(2)

LONG-TERM SCHEDULER (OR JOB SCHEDULER) Selects which processes should be brought into the

ready queue; these processes are spooled to a mass-storage (disk) where they are kept for later execution.

Controls the degree of multiprogramming

Page 26: 23565104 process-management(2)

LONG TERM SCHEDULER: (CONT) Must make careful selection among the processes (a

good process mix).

Processes can be described as either: I/O bound process – spends more time doing I/O than

computations, may short CPU bursts

CPU bound process – spends more time doing computations, few very long CPU bursts.

Page 27: 23565104 process-management(2)

SHORT-TERM SCHEDULER

Known as the CPU scheduler.

Selects which process should be executed next and allocates the CPU.

Page 28: 23565104 process-management(2)

MEDIUM-TERM SCHEDULER (SWAPPER)

Involves suspending or resuming processes by swapping or rolling them out of or into memory.

Swapping Removing a process from the memory.

Page 29: 23565104 process-management(2)

MEDIUM-TERM SCHEDULER

Page 30: 23565104 process-management(2)

THREAD: DEFINITION

A basic unit of CPU utilization Comprises a thread ID, program counter,

register set, and a stack. Process types:

Single-threaded – performs one task at a time Multithreaded – performs more than one task at

a time.

Page 31: 23565104 process-management(2)

EXAMPLES OF THREAD

Web browser One thread – displays images/text Another thread – retrieves data from network

Word processor One thread – displays graphics Another thread – responds to user keystrokes Another thread – performs spelling and grammar