Process Management
Process Management
In a distributed environment process management deals with the best use of the processor resources of the entire system by sharing them among all the processes. There are three important concepts used to achieve this goal:
1.Processor Allocation. 2.Process Migration. 3.Threads.
Process MigrationIt is the relocation of the process from the source node to the destination node to which it has been assigned.Process migration involves the following steps:
1. Selection of the process that has to be migrated.
2. Selection of the destination node to which the process has to be migrated.
3. Actual transfer of the process node to the selected destination node.
Desirable features of good process migration
Transparency 1.Object Access Level 2. System call & Interprocess
communication levelMinimal InterferenceMinimal Residual dependenciesEfficiencyRobustnessCommunication between co-processes of a job
Process transfer mechanisms..Four major sub-activities are involved in the process migration:
i) Freezing the process at its source node and restarting the process at the destination node.
ii) Transfer of the process address space from the source to the destination.
iii) Forwarding the messages meant for the migrant process.
iv) Handling the cooperation between the processes that have been seperated due to process migration
Mechanisms for freezing and restarting a process:
Immediate and delayed blocking of the process.Fast & slow I/O operationsInformation about open files.Reinstantiating the process on the destination node.
Address space transferring mechanisms.
Total freezingPretransferringTransfer on reference
Message forwarding mechanismsEnsure that all pending, en-route and future messages arrive at process’s new location.Messages to be forwarded can be classified into :
i. Message received at source node after process’s execution stopped on its source node and not yet started on destination node.Message received at source after execution started on destination.Messages to be sent to migrant process from any other node after it has started executing on destination node.
Mechanisms for message forwarding
Mechanism of resending messageOrigin site mechanismLink traversal mechanismLink update mechanism
Mechanisms for handling co-processes
Disallowing separation of the of co-processes.Home node or origin site concept.
Process Migration in Heterogeneous environment
Homogeneous environment – consistent data interpretation, no need of data translationHeterogeneous environment – data must be translated from source CPU format to destination CPU format.
- heterogeneous sys having ‘n’ CPU types must have ‘n(n-1)’ pieces of translation s/w.
External data representation
Processor type 1
Processor type 4
Processor type 3
Processor type 2
1
3
2
456
8
7
Serializing
Deserializing
Bounds complexity of translation s/w
Issues in handling Floating point number representation
Handling Exponent
-problem with design of external data representation.
-guarantee that external data representation have at least as many bits as longest exponent of any processor in the distributed sys.
Handling Mantissa
Handling Signed- infinity & signed-zero representation
Advantages of Process Migration
Reducing avg. response time of processorsSpeeding up individual jobsGaining higher throughputUsing resources effectivelyReducing n/w trafficImproving Sys. ReliabilityImproving Sys. Security
Threads
Threads A thread is a light-weight process (LWP), a means of achieving
multitasking. LWP shares all (or most of) its logical address space and
system resources with other processes and has its own private Process ID and parenthood relationships with other processes.
A LWP is scheduled as a regular process.
Advantages of Threads Creating a thread is cheaper than a process (~10-20 times) Switching to a different thread in same process is (much)
cheaper (5-50 times). Threads allow parallelism to be combined with sequential
execution and blocking system calls. Threads within same process can share data and other
resources more conveniently and efficiently .
Thread Implementation
Combining kernel-level lightweight processes and user-level threads.
Multithreaded Servers
Three ways to construct a server.
Model Characteristics
Single-threaded processNo Parallelism, blocking system calls
Finite-state machineParallelism, nonblocking system calls
Group of threads Parallelism, blocking system calls
Models for organizing threads
Depending on the application’s needs ,the threads of a process of the application can be organized in different ways.
Three commonly used ways to organize the threads of a process are:
Dispatcher-workers model Team model Pipeline model
Dispatcher-workers model: In this model ,the process consists of a single dispatcher
thread and multiple worker threads.
Dispatcher-worker model.
Models for organizing threads Contd..Team Model:
All the threads behave as equals as there is no dispatcher-worker relationship for processing client’s requests.
Each thread gets and processes client’s requests on it’s own.
This model is used for implementing specialized thread within the process.
Pipeline Model : In this model the threads of the process are pipelined so that
the output generated by the first thread is used for processing by the second thread and the output generated by the second thread is used for processing by the third thread and so on.
Issues in designing a Threads package Threads Creation:
Threads can be created either statically or dynamically. Static approach : In the static approach, the number of the threads of a process remains fixed
for it’s entire lifetime.
Dynamic approach: The number of threads of a process keeps changing dynamically.
Threads Termination: Thread may either destroy itself when it finishes it’s job by making an exit
call or can be killed from outside by using the kill command.
Threads Synchronization: Some mechanism must be used to prevent multiple threads from trying to
access the same data simultaneously. For this to occur safely ,each thread must ensure that it has exclusive access for this variable for some time.
Issues in designing a Threads package-Contd
A segment of the code in which a thread may be accessing some shared variables is called critical region.Hence the threads using the same data must be mutually exclusive in time.
Two mostly used mutually exclusive techniques :i) mutex variableii) condition variable
i) Mutex variable:• A mutex variable is like a binary semaphore that is always in
one of the two states ,locked and unlocked.• A thread that wants to execute in a critical region performs a
lock operation on the corresponding mutex variable.
• Only one thread can hold a particular lock at a time. Once a thread acquires a lock, other threads cannot get that same lock until the first thread releases the lock.
• If the mutex variable is already locked ,then either the thread is blocked and entered in the queue or status code indicating failure is returned to the thread.
Disadvantage: Their use is limited to guarding entries to critical regions.
ii) Condition variable: Condition variable is associated with the mutex variable and reflects the
boolean state of the variable. Wait and Signal are the two operations provided for a condition variable.
Issues in designing a Threads package-Contd
Issues in designing a Threads package-Contd..
When a thread performs a wait operation on a condition variable,the associated mutex variable is unlocked ,and the thread is blocked until a signal operation is performed indicating that the event being waited is occurred.
When a thread performs a signal operation on a condition variable,the
associated mutex variable is locked ,and the thread that was blocked waiting on the condition variable starts executing in the critical region.
Threads scheduling: Priority Assignment facility: In this facility, priority is assigned to various threads of an application to ensure that the important ones can be run on higher priority. The priority based scheduling is either pre-emptive or non-preemptive.
Issues in designing a Threads package-Contd..
Flexibility to vary quantum size dynamically: A scheduling scheme may vary the size of the time quantum inversely with
the total number of threads in the system to timeshare the CPU cycles among the threads.
Handoff Scheduling: This mechanism allows a thread to name it’s successor. Affinity Scheduling: In this scheme,a thread is scheduled on the CPU it last ran on and that part of the address space is still in that CPU’s cache.
Signal Handling: The signal provide software generated interrupts and exceptions. Interrupts are externally generated disruptions of a thread or a
process,whereas exceptions are caused by the occurrence of unusual conditions using a thread’s execution.
Implementation of Thread Package
Thread package can be implemented either in user space or in kernel depending upon which there are two approaches• User level approach• Kernel level approach
User Level Approach
User space consists of runtime systems that is a collection of thread management routines.
Run time systems maintains status information table to keep track of status of each thread.
This table has one entry per thread consisting of fields for register values, state, priority and other information of thread.
Calls of thread packages are maintained as call to runtime system procedures that performs the functions corresponding to calls.
Two level scheduling is performed in this approach.
User Level Approach contd…
Scheduler in the kernel allocates quanta to heavy weight process and divides quantum allocated to the process among the threads allocated to the process.
Existence of the thread is made invisible to the kernel.
Used by SunOS 4.1 lightweight processes package.
Advantages of User level approach
Thread package can be implemented on top of an existing operating system that does not support threads
Due to two level scheduling, users have flexibility to use their own customized algorithm to schedule the threads of process as a result of which user can design most appropriate algorithm for the application.
Switching the context from one thread to another is faster.
Disadvantages of User level approach
Use of round Robin scheduling policy to timeshare the CPU cycles among the threads on a quantum-by quantum basis is not possible due to lack of lack of clock interrupts within a single process.
Implementation of blocking system calls is not straightforward because if thread directly makes a blocking system calls all threads of the process will be stopped and kernel will schedule another process to run.
Kernel Level Approach
No runtime system is used and threads are managed by kernel.
Thread status information table is maintained within the kernel.
When thread blocks kernel selects another thread that may belong to either to the same process previously running or to different process.
Existence of thread is known to the kernel and single level scheduling is used.
Advantages of Kernel Level Approach
Implementation of Round robin scheduling policy is more practicable as clock interrupts periodically and kernel can keep track of amount of CPU time consumed by thread. When thread finishes it can be interrupted by kernel and CPU can be given to another thread.
Implementation of blocking system calls is straightforward because when thread makes a call ,it traps to the kernel where it is suspended and kernel starts a new thread.
Disadvantages of Kernel Level Approach
Concepts of thread can be incorporated in design of kernel of operating system as a result of which thread package cannot be incorporated.
Users do not have flexibility of choosing their own scheduling algorithm because single level scheduler is used that is built into kernel.
Switching the context from one thread to another is not fast because trap to the kernel is laid for it.
Thread management
Library procedures for managing threads in Thread package are: pthread_create: to create a new thread in a new address space
as a calling thread. This thread executes concurrently with the parent thread.
pthread_exit: to terminate the calling thread. pthread_join: to cause the calling thread to block itself until the
thread specified in this routine arguments terminates. pthread_cancel: used by thread to cancel another thread. Pthread_detach: used by parent thread to disown the child
thread.
Threads Synchronization
DCE threads package provides support for both mutex variables and condition variables for thread synchronization.Mutex variables are used when access to a shared resource by multiple threads.
The DCE threads package supports foll.mutex variables Fast: It is the one that causes the thread to block when the
thread attempts to lock an already locked mutex variable. Recursive: it is the one that allows thread to lock an already
locked mutex variable. Nonrecursive:It is the one that neither allows the thread to lock
an already locked mutex variable nor causes the thread to block.
Threads Synchronization contd…
DCE thread calls for the thread synchronization: pthread_mutex_init:It is used to dynamically create a mutex
variable. pthread_mutex_destroy:It is used to dynamically delete a mutex
variable. pthread_mutex_lock:It is used to lock a mutex variable. pthread_mutex_unlock:It is used to unlock a mutex variable. pthread_cond_init:It is used to dynamically create mutex variable. pthread_cond_destroy:It is used to dynamically destroy a mutex
variable. pthread_cond_signal:It is used to wake up a thread waiting on a
condition variable. pthread_cond_broadcast:It is used to wake up all threads waiting
on condition variables.
Threads Scheduling
Supports priority based thread scheduling.
It allows the user to specify not only the priorities for individual threads but also for scheduling algorithms.
Threads scheduling algorithms are:
First in,first out (FIFO): First thread of the first nonempty highest priority queue is always selected to run.It continues to execute until it either blocks or exits.
Round Robin: First nonempty highest priority queue is located. Each thread is run for a fixed quantum.
Default: Threads are run one after the another using time-sliced,round robin algorithm.The quantum allocated to the thread depends upon the priority.
Signal Handling
Signals may be generated due: Exceptional condition occurring due to thread`s execution
such as floating-point exception which is handled by thread in which it occurs.
External interrupts when user interrupts by hitting a key on the keyboard.
DCE also includes POSIX sigwait and sigaction services for signal handling.
sigwait allows the thread to block until one of the specified set of interrupt-based signals is delivered.
sigation allows for per-thread handlers to be installed for catching exception based signals.
Recommended