COMP3891

Processes and Threads

We often require an operating system to be able to:

Overview of Process Model

Processes

Threads

Multiprogramming

Implementation of Processes

A processes’ information is stored in a process control block (PCB). PCBs together form a process table.

Example Process Table Entry Fields

|Process Management|Memory Management|File Management| |–|–|–| |Registers|Pointer to text segment|Root directory| |Program counter|Pointer to data segment|Working directory| |Program status word|Pointer to stack segment|File descriptors| |Stack pointer||File descriptors| |Process state||User ID| |Priority||Group ID| |Scheduling parameters||| |Process ID||| |Parent process||| |Process group||| |Signals||| |Time when process started||| |CPU time used||| |Children’s CPU time||| |Time of next alarm|||

Lifecycle of a Process

Process Creation Causes

Process Termination Conditions

Process/Thread States

Events That Cause Process Transitions

Scheduler

Scheduler decides which of the Ready processes to run. There are various algorithms for scheduling.

Two Queue Algorithm

Multi Queue Algorithm

Thread Model

Thread vs Process

|Per process items|Per thread items| |-|-| |Address space|Program counter| |Global variables|Registers| |Open files|Stack (local variables)| |Child processes|State| |Pending alarms|| |Signals and signal handlers|| |Accounting information||

Thread Usage

|Model|Characteristics| |-|-| |Threads|Parallelism, blocking system calls| |Single-threaded process|No parallelism, blocking system calls| |Finite-state machine|Parallelism, nonblocking system calls, interrupts|

Why Threads?