Chapter 3 Processes
Chapter 3 Processes
1
Introduction
2
Introduction(con’t…)
3
Introduction(con’t…)
4
Introduction(con’t…)
5
3.1 Threads(con’t…)
What is tread?
A thread is the smallest unit of execution within a process.
Or a thread is a segment of a process
Threads allow for parallelism within a process
It is good for applications that require concurrent tasks
a process can have multiple threads
6
3.1 Threads
Types of tread:
Single treaded process
Multi treaded process
A process has an address space (containing program text and data) and a
single thread of control, as well as other resources such as open files, child
processes, etc.
three processes each with one thread one process with three threads 7
3.1 Threads(con’t…
each thread has its own program counter, registers, stack, and
state;
But, all threads of a process share address space, global
variables and other resources such as open files, etc.
8
3.1 Threads
9
3.1 Threads (con’t…)
10
3.1 Threads (con’t…)
11
3.1 Threads (con’t…)
non-blocking system.
distributed systems
We illustrate this point by taking a closer look at multithreaded
2. Multithreaded Servers
12
3.1.1.Threads in Distributed Systems (con’t…)
1. Multithreaded Clients
A typical example where this happens is in Web browsers, in
which.
Fetching different parts of a page can be implemented as a
separate thread,
Each thread sets up a separate connection to the server
Or each opening pages has its own TCP/IP connection to
the server or to replicated server
each can display the results as it gets its part of the page
Summary: multithreaded Web browsers several
in
connections can be opened simultaneously.
13
3.1.1.Threads in Distributed Systems (con’t…)
2. Multithreaded Servers
Multithreading in distributed systems can be found at the
server side.
In distributed system, servers can be constructed in three
ways
1. Single-threaded server
2. Multithreaded server
3. Finite-state machine
14
3.1.1.Threads in Distributed Systems (con’t…)
15
3.1.1.Threads in Distributed Systems (con’t…)
2. Multithreaded server:
Multithreads are more important for implementing servers
e.g., a file server Steps
The dispatcher thread reads incoming requests
Examining the request
The server chooses an idle worker thread and hands it the
request
3. Finite-state machine
Please note that in the first two possible designs, there is
blocking system calls
A third possibility is to run the server as a big finite-
state machine.
Instead of blocking, it records the state of the current request
in a table and then gets/proceeds to the next request.
Or
if threads are not available in server
it gets a request,
examines it,
tries to fulfill the request from cache, else sends a request
to the file system;
17
3.1.1.Threads in Distributed Systems (con’t…)
Model Characteristics
Single-threaded server No parallelism, blocking system calls
Parallelism, blocking system calls
Multithreads server
(thread only)
Parallelism, nonblocking system
Finite-state machine
calls
18
3.2. Client: General Design Issues
Reading Assignment
19
3.3 Servers: General Design Issues
Issues
1. How to organize servers?
2. Where do clients contact a server?
3. Whether and how a server can be interrupted
4. Whether or not the server is stateless
20
3.3 Servers: General Design Issues (con’t…)
1. How to organize servers?
Two primary types of server architectures are Iterative Servers and Concurrent
Servers.
Iterative server
the server itself handles the request and returns the result
How It Works
Server waits for a client request.
Accepts a single request from a client.
Processes the request.
Sends the response back to the client.
Moves to the next request
Disadvantage: Blocking, poor scalability, and Not Suitable for High
Loads
Concurrent server
it passes a request to a separate process or thread and waits for the next incoming
request;
Responds to clients simultaneously
e.g., a multithreaded server
21
3.3 Servers: General Design Issues (con’t…)
22
3.3 Servers: General Design Issues (con’t…)
23
3.3 Servers: General Design Issues (con’t…)
24
3.3 Servers: General Design Issues (con’t…)
25
3.4 Code Migration
26
3.4.1 Reasons for Migrating Code
Traditionally, code migration in distributed systems took place in the
form of process migration in which an entire process was moved
from one machine to another.
Problem: Performance
Solution: using code migration
move only code between machines
27
3.4.2. Models for Migrating Code
To get a better understanding of the different models for
code migration, we have to understand segments in a
process.
A process consists of three segments:
Code segment
Contains the set of instructions
Resource segment
Contains references to external resources such as files,
printers, devices, and so on.
Execution segment
Is used to store the current execution state of a process
consisting of private data, the stack, and the program
counter
28
3.4.2. Models for Migrating Code(con’t…)
There two models for migrating conde between machines:
1. Weak Mobility
2. Strong Mobility
29
3.4.2. Models for Migrating Code(con’t…)
1. Weak Mobility:
transfer only the code segment and may be some
initialization data; in this case a program always starts
from its initial stage, e.g. Java Applets
execution can be by the target process (in its own
address space like in Java Applets) or by a separate
process
30
3.4.2. Models for Migrating Code(con’t…)
2. Strong Mobility:
transfer code and execution segments; helps to migrate a
process in execution
can also be supported by remote cloning; having an exact copy
of the original process and running on a different machine;
executed in parallel to the original process; UNIX does this by
forking a child process
31
3.4.2. Models for Migrating Code(con’t…)
More on models for migration
migration can be
sender-initiated: the machine where the code resides
or is currently running; e.g., uploading programs to a
server; may need authentication or that the client is a
registered one
receiver-initiated: by the target machine; e.g., Java
Applets; easier to implement
32
3.4.2. Models for Migrating Code(con’t…)
Summary of models of code migration
34
3.4.3. Migration and Local Resources(cont…)
actions to be taken with respect to the references to local resources when migrating code
to another machine
36
Thank You!
37