32
Course Instructor: M. Daud Abdullah

OS Concepts Lec-2

Embed Size (px)

Citation preview

Course Instructor: M. Daud Abdullah

Processes

Multiprogramming of 4 programs

Conceptual model of 4 independent, sequential processes

Only one program active at any instant

Principal events that cause process creation

1. System initialization

Execution of process creation system

2. User request to create a new process

3. Initiation of a batch job

Conditions which terminate processes

1. Normal exit (voluntary)

2. Error exit (voluntary)

3. Fatal error (involuntary)

4. Killed by another process (involuntary)

A light weight process

Threads are a way for a program to split itself into two

or more simultaneously or (pseudo-simultaneously)

running tasks

Threads : Process

Description

Example Systems

1:1

Each thread of execution is a

unique process with its own

address space and resources.

Traditional UNIX

implementations

M:1

A process defines an address

space and dynamic resource

ownership. Multiple threads

may be created and executed

within that process.

Windows NT, Solaris,

OS/2,

OS/390, MACH

Threads : Process

Description

Example Systems

1:M

A thread may migrate from one

process environment to

another. This allows a thread

to be easily moved among

distinct systems.

Ra (Clouds), Emerald

M:M

Combines attributes of M:1

and 1:M cases

TRIX

1 to 1 Model

Many to 1 Model

Many to Many Model

(a): Three processes each with one thread

(b): One process with three threads

All thread management is done by the application

The kernel is not aware of the existence of threads

Thread management is done by User-Level threads

library

◦ Three primary Thread libraries

1. Posix Pthread

2. Win32 Threads

3. Java Threads

Windows XP, Linux, and Solaris are examples

of this approach

Kernel maintains context information for the

process and the threads

Scheduling is done on a thread basis supported

by kernel

• Items shared by all threads in a process

• Items private to each thread

A word processor with three threads

A user level thread package

A thread package managed by the kernel

States associated with a change in thread state

◦ Spawn

Spawn another thread

◦ Block

◦ Unblock

◦ Finish

Deallocate register stacks and context

Two Independent Schedulers

One single scheduler

Possible scheduling of user-level threads ◦ 50-msec process quantum

◦ Threads run 5 msec/CPU burst

Possible scheduling of kernel-level threads ◦ 50-msec process quantum

◦ threads run 5 msec/CPU burst

Takes less time to create a new thread than a

process

Less time to terminate a thread than a process

Less time to switch between two threads

within the same process

Since threads within the same process share

memory and files, they can communicate with

each other without invoking the kernel

Race Conditions

Two processes want to access shared memory

at same time

Four conditions to provide Mutual Exclusion

1. No two processes simultaneously in critical region

2. No assumptions made about speeds or numbers of CPUs

3. No process running outside its critical region may block

another process

4. No process must wait forever to enter its critical region

Mutual exclusion using critical regions

Proposed solutions to critical region problems

1. Process 0

2. Process 1