download

Matakuliah
Tahun
Versi/Revisi
: T0316/sistem Operasi
: 2005
:5
Pertemuan 4
Proses dan Threads
1
Learning Outcomes
Pada akhir pertemuan ini, diharapkan mahasiswa
akan mampu :
• Mahasiswa dapat menjelaskan konsep proses
dan threads (C2)
2
Outline Materi
Process model
Process creation
Process termination
Process hierarchies
Process states
Implementation process
Thread model
Thread usage
Implementation threads
3
PROCESS
PROCESS
- Multiprogramming
- Pseudoparallelism
- Multiprocessor
PROCESS MODEL
- Sequential process
- Multiprogramming
- CPU switching
- Program counter
Process vs program
4
• Multiprogramming of four programs
• Conceptual model of 4 independent, sequential
processes
• Only one program active at any instant
5
PROCESS CREATION
Principal events that cause process creation
1. System initialization
2. Execution of a process creation system
3. User request to create a new process
4. Initiation of a batch job
- Foreground vs background process
- Fork system call
6
PROCESS TERMINATION
Conditions which terminate processes
1. Normal exit (voluntary)
2. Error exit (voluntary)
•
Eg. Division by 0, illegal instruction, reference
to memory
3. Fatal error (involuntary)
•
Eg. Non-existing file
4. Killed by another process (involuntary)
•
Eg. Ctrl-break
7
Process Hierarchies
Parent creates a child process, child processes can
create its own process
Forms a hierarchy
UNIX calls this a "process group“
Eg. init
Windows has no concept of process hierarchy
all processes are created equal
8
Process States
Possible process states
running
blocked
ready
Transitions between states shown
9
Lowest layer of process-structured OS
handles interrupts, scheduling
Above that layer are sequential processes
10
Implementation of Processes
Fields of a process table entry
11
Interrupt vector
Interrupt handling and scheduling
Skeleton of what lowest level of OS does when an
interrupt occurs
12
Threads
- Multiple threads of control in the same address space in quasiparralel, as though they are separate processes
(a) Three processes each with one thread
(b) One process with three threads
13
The Thread Model
- Threads allow multiple executions to take
place in the same process environment
-
Lightweight process  because threads
have some properties of processes
-
Multithreading  allowing multiple
threads in the same process
14
Items shared by all threads in a process
Items private to each thread
15
Each thread has its own stack
16
Thread Usage
Why?
• Multiple sequential threads can be executed in
quasi-parallel
• Easier to create and to delete
• Performance
• Useful on systems with multiple CPU
17
A word processor with three threads
18
- Multithreaded web server:
(a) Dispatcher thread
(b) worker thread
19
Implementing Threads in User Space
Advantages:
Allow each process to have
its own scheduling algorithm
Performance
Disadvantages:
Implementation of blocking
system calls
No other threads can run
unless the first thread
voluntarily gives up the CPU
20
Implementing Threads in the Kernel
Advantages:
Does not need a new nonblocking system calls
Disadvantages:
Greater cost of creating and
destryoing threads
21
Hybrid Implementations
Multiplexing user-level threads onto kernel- level
threads
22