Chapter 2
Chapter 2
Chapter 2
Processes
Processes Threads
Processes
We take a closer look at how the different types of processes play a crucial role in
distributed systems.
Introduction to threads
Processes Threads
Introduction to threads
Basic idea
We build virtual processors in software, on top of physical processors:
Processor: Provides a set of instructions along with the capability of
automatically executing a series of those instructions.
Thread: A minimal software processor in whose context a series of
instructions can be executed.
Process: A software processor in whose context one or more threads
may be executed.
Introduction to threads
Processes Threads
Context switching
Contexts
• Processor context: The minimal collection of values stored in the
registers of a processor used for the execution of a series of instructions
(e.g., stack pointer, addressing registers, program counter).
• Thread context: The minimal collection of values stored in registers and
memory, used for the execution of a series of instructions (i.e., processor
context, state).
• Process context: The minimal collection of values stored in registers
and memory, used for the execution of a thread (i.e., thread context).
Introduction to threads
Processes Threads
Introduction to threads
Processes Threads
1. Threads share the same address space. Thread context switching can be done
entirely independent of the operating system.
2. Process switching is generally (somewhat) more expensive as it involves getting
the OS in the loop.
3. Creating and destroying threads is much cheaper than doing so for processes.
Introduction to threads
Processes Threads
User-space solution
• All operations can be completely handled within a single process ⇒
implementations can be extremely efficient.
• All services provided by the kernel are done on behalf of the process in
which a thread resides ⇒ if the kernel decides to block a thread, the
entire process will be blocked.
• Threads are used when there are many external events: threads block
on a per-event basis ⇒ if the kernel can’t distinguish threads, how can it
support signaling events to them?
Introduction to threads
Processes Threads
Conclusion – but
Try to mix user-level and kernel-level threads into a single concept,
however, performance gain has not turned out to generally outweigh the
increased complexity.
Introduction to threads
Processes Threads
Better structure
• Most servers have high I/O demands. Using simple, well-understood
blocking calls simplifies the structure.
• Multi-threaded programs tend to be smaller and easier to understand
due to simplified flow of control.
Overview
Model Characteristics
Virtualization
Virtualization is important:
• Hardware changes faster than software
• Ease of portability and code migration
• Isolation of failing or attacked components
Principle of virtualization
Processes Virtualization
Mimicking interfaces
Four types of interfaces at three different levels
1. Instruction set architecture: the set of machine instructions, with two
subsets:
• Privileged instructions: allowed to be executed only by the
operating system.
• General instructions: can be executed by any program.
2. System calls as offered by an operating system.
3. Library calls, known as an application programming interface (API)
Principle of virtualization
Processes Virtualization
Ways of virtualization
Differences
a) Separate set of instructions, an interpreter/emulator, running atop an OS.
b) Low-level instructions, along with bare-bones minimal operating system
c) Low-level instructions, but delegating most work to a full-fledged OS.
Principle of virtualization
Processes Virtualization
Containers
Concurrent servers are the norm: they can easily handle multiple requests,
notably in the presence of blocking operations (to disks or other servers).
Contacting a server
Most services are tied to a specific port
telnet 23 Telnet
Out-of-band communication
Issue
Is it possible to interrupt a server once it has accepted (or is in the process of
accepting) a service request?
Stateful servers
Keeps track of the status of its clients:
Record that a file has been opened, so that prefetching can be done
Knows which data a client has cached, and allows clients to keep
local copies of shared data
Code migration
Code migration involves passing programs and data: when a program migrates while running,
its status, pending signals, and other environment variables such as the stack and the
program counter also have to be moved.
Reasons to migrate code
Load distribution
● Ensuring that servers in a data center are sufficiently loaded (e.g., to
prevent waste of energy)
● Minimizing communication by ensuring that computations are close to
where the data is (think of mobile computing).
Code migration
Processes Code migration
Code migration
Processes Code migration
Weak mobility: Move only code and data segment (and reboot
execution)
• Relatively simple, especially if code is portable
• Distinguish code shipping (push) from code fetching (pull)
Code migration
Processes Code migration
Code migration
Processes Code migration
Software agents: software processes or robots that can move around the
system
To do specific tasks for which they are specially programmed.
Web Crawlers
Virtual Personal Assistants
Surveillance agents
Robotic Process Automation (RPA) agents
Smart Home agents
Autonomous Vehicles
Antivirus agents
Buyer agents
etc.