Professional Documents
Culture Documents
03 Processes Threads
03 Processes Threads
CHAPTER 3:
PROCESSES AND
THREADS
Dr. Trần Hải Anh
Role of OS in process management
2
P P
P P P
P P P
P P
P P
OS
OS Machine OS
Machine Machine
P P P P
P P
P P
OS OS
Machine Machine
Virtualization
3
P P
P
P
OS
Machine A Machine B
Outline
4
¨ Process
¤ A program in execution
¤ Resources
n Execution environment, memory space, registers, CPU...
n Virtual processors
n Virtual memory
¤ Concurrency transparency
¤ Creating a process:
n Create a complete independent address space
n Allocation = initializing memory segments by zeroing a data segment,
copying the associated program into a text segment, setup a stack for
temporary data
¤ Switching the CPU between processes: Saving the CPU context +
modify registers of MMU, ...
Thread
7
¨ Thread package:
¤ Creating threads (1)
¤ Destroying threads (2)
¤ Kernel mode:
Lightweight processes (LWP)
14
¨ Single-threaded server
¤ One request at one moment
¤ Sequentially
Thread 2 makes
requests to server
Receipt & Input-output
Thread 1 queuing
generates
results
T1
Requests
N threads
Client
Server
Server dispatcher
19
Multithreaded Server
20
Model Characteristics
Threads Parallelism, Blocking system calls
Single-threaded process No parallelism, blocking system calls
Finite-state machine Parallelism, Non-blocking system calls
Multithreaded Client
23
VM
2
VM2
LinuxVM
VM
1
VM1
LinuxVM Windows VM
App
Windows VM App
Hypervisor
Hypervisor Host OS
Hardware Hardware
main()
{
// Open the display
Display *dpy = XOpenDisplay(NIL);
assert(dpy);
¨ Organize server
¤ Iterative server
¤ Concurrent server
¨ Find server:
¤ End-point (port)
¤ Deamon
¤ Superserver
¨ Interrupt server
¨ Stateless & stateful
server
Inetd
51
username
socket and
protocol
Example:
52
¨ A program errorLogger.c
Configure inetd
53
¨ Improve performance
¤ Server code to client
¤ Client code to server
¤ Exploiting parallelism
Code migration models
56