Operating System: Chapter 2 - Processes and Threads presents about Processes (The Process Model, Process Creation, Process Termination, Process Hierarchies, Process States,...), Threadsm, Interprocess communication, Classical IPC problems, Scheduling.
Trang 2ProcessesThe Process Model
• Multiprogramming of four programs
• Conceptual model of 4 independent, sequential processes
• Only one program active at any instant
Trang 5Process Hierarchies
• Parent creates a child process, child processes can create its own process
• Forms a hierarchy
– UNIX calls this a "process group"
• Windows has no concept of process hierarchy
– all processes are created equal
Trang 8Implementation of Processes (1)
Fields of a process table entry
Trang 9Implementation of Processes (2)
Skeleton of what lowest level of OS does when an
interrupt occurs
Trang 10ThreadsThe Thread Model (1)
(a) Three processes each with one thread
(b) One process with three threads
Trang 11The Thread Model (2)
• Items shared by all threads in a process
• Items private to each thread
Trang 12The Thread Model (3)
Each thread has its own stack
Trang 13Thread Usage (1)
A word processor with three threads
Trang 14Thread Usage (2)
A multithreaded Web server
Trang 16Thread Usage (4)
Three ways to construct a server
Trang 17Implementing Threads in User Space
A userlevel threads package
Trang 18Implementing Threads in the Kernel
A threads package managed by the kernel
Trang 19Hybrid Implementations
Multiplexing userlevel threads onto
kernel level threads
Trang 22Making SingleThreaded Code Multithreaded (1)
Conflicts between threads over the use of a global variable
Trang 23Making SingleThreaded Code Multithreaded (2)
Threads can have private global variables
Trang 24Interprocess Communication
Race Conditions
Two processes want to access shared memory at same time
Trang 26Critical Regions (2)
Mutual exclusion using critical regions
Trang 27Mutual Exclusion with Busy Waiting (1)
Proposed solution to critical region problem
(a) Process 0. (b) Process 1.
Trang 28Mutual Exclusion with Busy Waiting (2)
Peterson's solution for achieving mutual exclusion
Trang 29Mutual Exclusion with Busy Waiting (3)
Entering and leaving a critical region using the
TSL instruction
Trang 30Sleep and Wakeup
Producerconsumer problem with fatal race condition
Trang 31Semaphores
The producerconsumer problem using semaphores
Trang 32Mutexes
Implementation of mutex_lock and mutex_unlock
Trang 33Monitors (1)
Example of a monitor
Trang 35Monitors (3)
Solution to producerconsumer problem in Java (part 1)
Trang 36Monitors (4)
Solution to producerconsumer problem in Java (part 2)
Trang 37Message Passing
The producerconsumer problem with N messages
Trang 40Dining Philosophers (2)
A nonsolution to the dining philosophers problem
Trang 41Dining Philosophers (3)
Solution to dining philosophers problem (part 1)
Trang 42Dining Philosophers (4)
Solution to dining philosophers problem (part
2)
Trang 43The Readers and Writers Problem
A solution to the readers and writers problem
Trang 44The Sleeping Barber Problem (1)
Trang 45The Sleeping Barber Problem (2)
Solution to sleeping barber problem.
Trang 47Introduction to Scheduling (2)
Scheduling Algorithm Goals
Trang 48Scheduling in Batch Systems (1)
An example of shortest job first scheduling
Trang 49Scheduling in Batch Systems (2)
Three level scheduling
Trang 51Scheduling in Interactive Systems (2)
A scheduling algorithm with four priority classes