Process context
The context of a process is its state. It comprises of text (program code), all global variables
and data structures ( data + bss), all dynamic memory (heap), context of user and kernel
stacks and all machine registers.
Context-switching
When a process is running, the system is said to be in the context of that process.
When the kernel decided to execute another process, it does a context-switch.
The kernel has to save enough information so that it can switch back to the earlier process
and continue executing exactly where it left off.
When a process executes a system call and has to change from the user-mode to kernel
mode, context-switching occurs.
Enabling concurrently sharing of the same CPU and other H/W resources by multiple
processes, context-switching provides concurrency transparency in a DS.
Context-Switching in IPC
User space
IPC requires kernel intervention
Process A will first switch from user-mode to kernel-mode Process A Process B
(S1)
S1: switch from user space to kernel space
Within the kernel, a process context-switch takes place
(S2)
S2: switch from process-context (A) to process-context (B) S1 S3
Process B can be activated by switching from kernel mode S2
to user mode
kernel space
S3: switch from kernel space to user space
Switching involves change of memory maps
Flushing of Transaction Look-aside Buffer (TLB)
TLB : cache of frequently-used memory address
translation)
Process Table and Process Control Blocks
A process is a program in memory along with dynamically allocated storage (heap), the
stack and the execution context comprising the state of processor – registers, PC etc.
Process has two compoments
1. Program + heap
2. stack + SP + PC + registers etc
2nd component is important for execution flow of the program
PC keeps track of which instruction to execute next
Instructions affect the registers
Subroutine call/return instructions and instructions that push or pop registers on the
stack on entry and exit for function call adjust contents of the stack and SP
This stream of instruction is the thread of execution of the process.
A traditional process has one thread of execution
Multi-threading
In a traditional OS, each process has an address space and a single thread of control or thread of
execution or simply a thread.
A process may be multi-threaded
Same program contains multiple concurrent threads of execution
As OS that supports multi-threading has a scheduler responsible for pre-empting and scheduling all
threads of all processes.
In a multi-threaded process all of its threads share the same memory or address space and open files.
Within the shared memory each thread get its own stack, sp, instruction pointer, registers etc.
Since memory is shared there is no memory protection among the threads in a process.
Switching back and forth among multiple multi-threaded processes, a system gives the illusion of parallel
processing.
In a DS main contribution of multi-threading is that it allows clients and servers overlap in communication
and local processing, resulting in a high performance.
Pure software engineering reason to use multi-threading is to structure a collection of cooperating threads.
PCB and TCB
An OS keeps track of process specific information
in PCBs in process table.
Thread specific information are stored in a data
structure called Thread Control Block (TCB).
Each PCB will be linked to a list of TCBs PCB PCB PCB
Information required by OS to store for each
thread TCB TCB TCB
Thread ID, Stored registers, SP, IP, Stack, Signal
mark
Priority (scheduling info) TCB TCB TCB
State: (running I blocked I terminated I ready )
Information shared among threads within a
process
Text segment, Data segment, Bss, Open file
descriptor, Signals
Current working directory
Methods of thread implementation:
User space threads
Threads are generally provided in the form of packages. User space
Consider a client server system. Server manages a huge database. If the client
needs to do many database operations involving large quantity of data, it may be
better to migrate part of the client application to server and send only the result.
Principle is: : process data closer to where those data reside.
Similarly, if a client needs to fill up forms, then validation part of the server can be
migrated to the client.
Exploit parallelism: A search query in the form of a mobile program moves from
site to site collect information or several copies of such a program is
simultaneously send to different sites. (Web crawler).
Dynamically configured DS
Traditional DS partitions applications into different parts and each part is allocated
to different executor apriori. It is a statically configured DS. (multi-layered C/S)
Let the server provide the client implementation. The client dynamically
downloads the implementation, goes through the initialization steps, invokes the
server.
This approach enables dynamic configuration of a DS. (Java applet/servlet)
Models for code migration
Weak mobility
Transfer only code segment and perhaps some initialization data
Transferred program is always started from the initial state.
Only requirement is that the target machine can execute the code (portability). Ex java
applet
Benefit: simlicity
Strong mobility
Transfer code segment and execution segment.
Running process can be stopped, migrated to the target machine, and resumed the
execution.
Sender or receiver initiated migration
Sender-initiated
Migration is initiated by the source machine, where the code currently resides or being
executed.
Uploading programs to a computer server
Search program across Internet to perform query at servers
Requires that the client is already registered and authenticated at the server. Because the
migrated code may access server’s resources.
Receiver-initiated
Migration is initiated by the target machine
Downloading a code (Java applets)
Instead of migrating a running process physically, remote cloning the process can be
done.
Migration and local resources
When migrating code, we often need to change references to resources, but cannot
affect process-to-resource binding. We need to consider resource-to-machine bindings.
Fugetta framework suggests three types of Resource-to-machine bindings
1. Unattached resources: can be easily moved between machines, typically data
files associated only with the code that is to be migrated.
2. Fastened resources: Moving & Copying is possible but only at relatively high cost.
Ex: local databases, complete websites etc.
Such resources are not dependent on current machines but infeasible to move them to
another environment.
Fixed resources : intimately bound to a specific machine or environment and cannot
be moved.
local devices, local comm. endpoints(sockets)
Combinations
Migration in heterogenous System
We assumed that migrated code can easily be executed at the target machine.
This assumption is true in case of homogeneous system
Migration is such system require that code segment can be executes on each
platform.
recompilation of the original source may be required.
Software Agents in DS
Collaboration Agents
autonomy + co-operation=> collaboration
Agents seek to achieve some common goal through collaboration.
eg. Meeting scheduler.
Each attendee is represented by a s/w agent.
Given all the individual constraints wrt time travel, place, personal agenda etc. separate
agents would collaborate and set up a meeting.
Inter-agent communication
Mobile agent
A mobile agent is simply an agent having the capability to move between different
machines.
Agents are autonomous and actively interact with the environment. There needs
strong mobility.
However, agents with weak mobility are also useful. ( Eg. D’agent)
Foundation for Intelligent Physical Agents (FIPA)
Interface agent
S/w agents that assists an end-user in the use of one or more applications are
interface agents.
It has an learning ability.
More interaction better assistance.
Information agents