Unit-2

advertisement
1
Unit-2
Concurrent Processes: Process Concept, Principle of Concurrency, Producer / Consumer
Problem, Critical Section Problem, Semaphores, Classical Problems in Concurrency, Inter
Processes Communication, Process Generation, Process Scheduling, Threads.
CPU Scheduling: Scheduling Concept, Performance Criteria, Scheduling Algorithm
Evolution, Multiprocessor Scheduling.
Process Management
Process Concept:
In computing, a process is an instance of a computer program that is being executed. It contains
the program code and its current activity. Depending on the operating system (OS), a process
may be made up of multiple threads of execution that execute instructions concurrently.
A computer program is a passive collection of instructions; a process is the actual execution of
those instructions. Several processes may be associated with the same program; for example,
opening up several instances of the same program often means more than one process is being
executed.
Multitasking is a method to allow multiple processes to share processors (CPUs) and other
system resources. Each CPU executes a single task at a time. However, multitasking allows each
processor to switch between tasks that are being executed without having to wait for each task to
finish. Depending on the operating system implementation, switches could be performed when
tasks perform input/output operations, when a task indicates that it can be switched, or on
hardware interrupts.
A common form of multitasking is time-sharing. Time-sharing is a method to allow fast response
for interactive user applications. In time-sharing systems, context switches are performed
rapidly. This makes it seem like multiple processes are being executed simultaneously on the
same processor. The execution of multiple processes seemingly simultaneously is called
concurrency.
For security and reliability reasons most modern operating systems prevent direct
communication between independent processes, providing strictly mediated and controlled interprocess communication functionality.
 A process can initiate a subprocess, which is a called a child process (and the initiating process is
sometimes referred to as its parent ). A child process is a replica of the parent process and
shares some of its resources, but cannot exist if the parent is terminated.
 Processes can exchange information or synchronize their operation through several methods of
interprocess communication ( IPC ).
2
Threads:
A thread of execution is the smallest sequence of programmed instructions that can be managed
independently by an operating system scheduler. A thread is a light-weight process. The implementation
of threads and processes differs from oneoperating system to another, but in most cases, a thread is
contained inside a process. Multiple threads can exist within the same process and share resources such
as memory, while different processes do not share these resources. In particular, the threads of a
process share the latter's instructions (its code) and its context (the values that its variables reference at
any given moment).
3
There are two types of threads : User threads and kernel threads
Multi-threading:
Multithreading computer central processing units have hardware support to efficiently execute
multiple threads. These are distinguished from multiprocessing systems (such as multi-core systems) in
that the threads have to share the resources of a single core: the computing units
Advantages
Some advantages include:

If a thread gets a lot of cache misses, the other thread(s) can continue, taking advantage of the
unused computing resources, which thus can lead to faster overall execution, as these resources
would have been idle if only a single thread was executed.

If a thread cannot use all the computing resources of the CPU (because instructions depend on each
other's result), running another thread can avoid leaving these idle.

If several threads work on the same set of data, they can actually share their cache, leading to better
cache usage or synchronization on its values.
multithreading aims to increase utilization of a single core by using thread-level as well as instruction-level
parallelism. As the two techniques are complementary, they are sometimes combined in systems with
multiple multithreading CPUs and in CPUs with multiple multithreading cores
―The ability of an operating system to execute different parts of a program, called threads, simultaneously.
The programmer must carefully design the program in such a way that all the threads can run at the same
time without interfering with each other. ―
4
Context Switch :
The time needed to switch from one job to another is known as context switch. A context switch is
the computing process of storing and restoring the state (context) of a Process so that execution
can be resumed from the same point at a later time. This enables multiple processes to share a
single CPU. This is an essential features of multitasking operating system.
Typically there are several tasks to perform in a computer system.
So if one task requires some I/O operation, you want to initiate the I/O operation and go on to the next
task. You will come back to it later.
This act of switching from one process to another is called a "Context Switch"
When you return back to a process, you should resume where you left off. For all practical purposes, this
process should never know there was a switch, and it should look like this was the only process in the
system.
To implement this, on a context switch, you have to



save the context of the current process
select the next process to run
restore the context of this new process.
What is the context of a process?





Program Counter
Stack Pointer
Registers
Code + Data + Stack (also called Address Space)
Other state information maintained by the OS for the process (open files, scheduling info, I/O
devices being used etc.)
All this information is usually stored in a structure called Process Control Block (PCB).
All the above has to be saved and restored.
What does a context_switch() routine look like?
context_switch()
{
Push registers onto stack
Save ptrs to code and data.
Save stack pointer
Pick next process to execute
Restore stack ptr of that process /* You have now switched the stack */
Restore ptrs to code and data.
Pop registers
Return
}
5
Process Operations
Process Creation
In general-purpose systems, some way is needed to create processes as needed during operation.
There are four principal events led to processes creation.




System initialization.
Execution of a process Creation System calls by a running process.
A user request to create a new process.
Initialization of a batch job.
Foreground processes interact with users. Background processes that stay in background sleeping
but suddenly springing to life to handle activity such as email, webpage, printing, and so on.
Background processes are called daemons. This call creates an exact clone of the calling process.
A process may create a new process by some create process such as 'fork'. It choose to does so,
creating process is called parent process and the created one is called the child processes. Only
one parent is needed to create a child process. Note that unlike plants and animals that use sexual
representation, a process has only one parent. This creation of process (processes) yields a
hierarchical structure of processes like one in the figure. Notice that each child has only one
parent but each parent may have many children. After the fork, the two processes, the parent and
the child, have the same memory image, the same environment strings and the same open files.
After a process is created, both the parent and child have their own distinct address space. If
either process changes a word in its address space, the change is not visible to the other process.
<Figure 3.2 pp.55 From Dietel>
Following are some reasons for creation of a process




User logs on.
User starts a program.
Operating systems creates process to provide service, e.g., to manage printer.
Some program starts another process, e.g., Netscape calls xv to display a picture.
Process Termination
6
A process terminates when it finishes executing its last statement. Its resources are returned to
the system, it is purged from any system lists or tables, and its process control block (PCB) is
erased i.e., the PCB's memory space is returned to a free memory pool. The new process
terminates the existing process, usually due to following reasons:




Normal Exist Most processes terminates because they have done their job. This call is
exist in UNIX.
Error Exist When process discovers a fatal error. For example, a user tries to compile
a program that does not exist.
Fatal Error An error caused by process due to a bug in program for example,
executing an illegal instruction, referring non-existing memory or dividing by zero.
Killed by another Process A process executes a system call telling the Operating
Systems to terminate some other process. In UNIX, this call is kill. In some systems
when a process kills all processes it created are killed as well (UNIX does not work this
way).
Process States
A process goes through a series of discrete process states.





New State The process being created.
Terminated State The process has finished execution.
Blocked (waiting) State When a process blocks, it does so because logically it cannot
continue, typically because it is waiting for input that is not yet available. Formally, a
process is said to be blocked if it is waiting for some event to happen (such as an I/O
completion) before it can proceed. In this state a process is unable to run until some
external event happens.
Running State A process is said t be running if it currently has the CPU, that is,
actually using the CPU at that particular instant.
Ready State A process is said to be ready if it use a CPU if one were available. It is
runable but temporarily stopped to let another process run.
Logically, the 'Running' and 'Ready' states are similar. In both cases the process is willing to run,
only in the case of 'Ready' state, there is temporarily no CPU available for it. The 'Blocked' state
is different from the 'Running' and 'Ready' states in that the process cannot run, even if the CPU
is available.
7
Process State Transitions
Following are six(6) possible transitions among above mentioned five (5) states
FIGURE

Transition 1 occurs when process discovers that it cannot continue. If running process
initiates an I/O operation before its allotted time expires, the running process voluntarily
relinquishes the CPU.
This state transition is:
Block (process-name): Running → Block.

Transition 2 occurs when the scheduler decides that the running process has run long
enough and it is time to let another process have CPU time.
This state transition is:
Time-Run-Out (process-name): Running → Ready.

Transition 3 occurs when all other processes have had their share and it is time for the
first process to run again
This state transition is:
Dispatch (process-name): Ready → Running.

Transition 4 occurs when the external event for which a process was waiting (such as
arrival of input) happens.
This state transition is:
8
Wakeup (process-name): Blocked → Ready.

Transition 5 occurs when the process is created.
This state transition is:
Admitted (process-name): New → Ready.

Transition 6 occurs when the process has finished execution.
This state transition is:
Exit (process-name): Running → Terminated.
Process Structure
Processes run in the background and provide a common language that allows the operating
system to interface with the installed hardware & software to support any applications running
on the system. A process is an environment in which a program executes.
Process is simply a unit of execution. Means to say for our sake how the things go it is unit
collectively task that accompalishes one particular need. It is really not unit because a unit
microprocessor operation is something else.
A Process is meant by its execution environment which is sensefull by saying that it is active
program entry that has its state and context, A share on resources defined by by computer system
like memory ,registers and others.
Microprocessor's convention says it is sequence of microoperations that run and perform on
job,And a well defined context at which instant it is executing the task. Process is active program
entry that takes a part of CPU. For more reasons go for OS fundas in any OS book or query me .
Rupesh K Joshi rupesh_joshi@sify.com,rupesh.joshi@gmail.com
9
A process consists of
1. An executable (i.e., code)
2. Associated data needed by
the program (global data,
dynamic data, shared data)
3. Execution context (or state)
of the program, e.g.,
- Contents of data
registers
- Program counter, stack
pointer
- Memory allocation
- Open file (pointers)
Stack Dynamic
data
data
Code
10
Process Control Block
Process Control Block (PCB, also called Task Controlling Block, Task Struct, or Switchframe) is a
data structure in the operating system kernel containing the information needed to manage a particular
process. The PCB is "the manifestation of a process in an operating system".
If the mission of the operating system is to manage computing resources on behalf of processes, then it
must be continuously informed about the status of each process and resource.
Each process is represented in os by a process control block , also called a task control block
11
Process Migration
It is the transfer of sufficient amount of the state of process from one machine to the target machine.
process migration is a specialized form of process management whereby processes are moved from
one computing environment to another. The most common application of process migration is
in computer clusters where processes are moved from machine to machine. Process migration is
implemented in, among others, OpenMosix. It was pioneered by the Sprite OS from .
Process migration in computing comes in two flavors:
Non-preemptive process migration
Process migration that takes place before execution of the process starts (i.e. migration whereby
a process need not be preempted). This type of process migration is relatively cheap, since
relatively little administrative overhead is involved.
Preemptive process migration
Process migration whereby a process is preempted, migrated and continues processing in a
different execution environment. This type of process migration is relatively expensive, since it
involves recording, migration and recreation of the process state as well as the reconstructing of
any inter-process communication channels to which the migrating process is connected.
Inter process communication
inter-process communication (IPC) is a set of methods for the exchange of data among
multiple threads in one or more processes. Processes may be running on one or more computers
connected by a network. IPC methods are divided into methods for message
passing, synchronization, shared memory, and remote procedure calls (RPC). The method of IPC used
may vary based on the bandwidth and latency of communication between the threads, and the type of
data being communicated.
There are several reasons for providing an environment that allows process cooperation:

Information sharing

Computational speedup

Modularity

Convenience

Privilege separation
IPC may also be referred to as inter-thread communication and inter-application communication.
The combination of IPC with the address space concept is the foundation for address space
independence/isolation.
12
IPC techniques include Named Pipes, File Mapping, Mailslot, Remote Procedure Calls (RPC), etc.
Principle of Concurrency
On a single processor machine the OS support for concurrency allows multiple application to share
resources in such a way that applications appear to run at a same time. since a typical application
does not consume all resources at a given time.
A careful coordination can make each application as if runs the entire machine
concurrency is a property of systems in which several computations are executing simultaneously, and
potentially interacting with each other. The computations may be executing on multiple cores in the
same chip, preemptively time-shared threads on the same processor, or executed on physically
separated processors. A number of mathematical models have been developed for general concurrent
computation including Petri nets, process calculi, the Parallel Random Access Machine model, the Actor
model and the Reo Coordination Language.
Concurrent processing is a computing model in which multiple processors execute instructions
simultaneously for better performance. Concurrent means something that happens at the same time as
something else. Tasks are broken down into subtasks that are then assigned to separate processors to
perform simultaneously, instead of sequentially as they would have to be carried out by a single
processor. Concurrent processing is sometimes said to be synonymous with parallel processing.
Classical synchronization problem
1)
The bounded buffer problem ( Procedure –Consumer Problem)
13
2)
3)
Readers writers Problem
Dining Philosophers Problem
1) The bounded buffer problem (Producer / Consumer Problem)
The producer-consumer problem (also known as the bounded-buffer problem) is a classic example of
a multi-process synchronization problem. The problem describes two processes, the producer and the
consumer, who share a common, fixed-size buffer used as a queue. The producer's job is to generate a
piece of data, put it into the buffer and start again. At the same time, the consumer is consuming the data
(i.e., removing it from the buffer) one piece at a time. The problem is to make sure that the producer won't
try to add data into the buffer if it's full and that the consumer won't try to remove data from an empty
buffer.
The solution for the producer is to either go to sleep or discard data if the buffer is full. The next time the
consumer removes an item from the buffer, it notifies the producer, who starts to fill the buffer again. In
the same way, the consumer can go to sleep if it finds the buffer to be empty. The next time the producer
puts data into the buffer, it wakes up the sleeping consumer. The solution can be reached by means
of inter-process communication, typically using semaphores. An inadequate solution could result in
a deadlock where both processes are waiting to be awakened. The problem can also be generalized to
have multiple producers and consumers.
The bounded buffer problem was used to illustrate the power of synchronization primitives. The code for
the producer process and consumer process mentioned below:
.shared data
Type item=………
Var buffer=…………
Full,empty,mutex: semaphore;
Nextp , nextc: item;
Full:=0 ; empty:=n; mutex:=1;
. producer process
Repeat
……
Produce an item in nextp
………….
Wait (empty);
Wait(mutex);
…………
Signal(mutex);
Signal(full);
14
Until false;
. consumer process
Repeat
Wait(full)
Wait (mutex);
………..
Remove an item from buffer to nextp;
……….
Signal(mutex);
Signal(empty);
…………..
Consume the item in nextc
………
Until false;
We assume that the pool consists of n buffers, each capable of holding one item.
The mutex semaphore provides mutual exclusion for accesses to the buffer pool and is initialized to the
value 1. The empty and full semaphores count the number of empty and full buffers.
The semaphores empty is initialized to the value n;
The semaphores full is initialized to the value 0.
2) Readers writers problem
the first and second readers-writers problems are examples of a common computing problem
in concurrency. The two problems deal with situations in which many threads must access the
same shared memory at one time, some reading and some writing, with the natural constraint that no
process may access the share for reading or writing while another process is in the act of writing to it. (In
particular, it is allowed for two or more readers to access the share at the same time.) A readers-writer
lock is a data structure that solves one or more of the readers-writers problems.
The first readers-writers problem
Suppose we have a shared memory area with the constraints detailed above. It is possible to protect the
shared data behind a mutual exclusion mutex, in which case no two threads can access the data at the
same time. However, this solution is suboptimal, because it is possible that a reader R1 might have the
lock, and then another reader R2 request access. It would be foolish for R2 to wait until R1was done
before starting its own read operation; instead, R2 should start right away. This is the motivation for
15
the first readers-writers problem, in which the constraint is added that no reader shall be kept waiting if
the share is currently opened for reading. This is also called readers-preference, with its solution below:
semaphore wrt=1,mutex=1;
readcount=0;
writer()
{
wait(wrt);
//writing is done
signal(wrt);
}
reader()
{
wait(mutex);
readcount++;
if(readcount==1)
wait(wrt);
signal(mutex);
///Do the Reading
///(Critical Section Area)
wait(mutex);
readcount--;
if(readcount==0)
signal(wrt);
signal(mutex);
}
The second readers-writers problem
Suppose we have a shared memory area protected by a mutex, as above. This solution is suboptimal,
because it is possible that a reader R1 might have the lock, a writer W be waiting for the lock, and then a
reader R2 request access. It would be foolish for R2 to jump in immediately, ahead of W; if that happened
often enough, W would starve. Instead, W should start as soon as possible. This is the motivation for
the second readers-writers problem, in which the constraint is added that no writer, once added to the
queue, shall be kept waiting longer than absolutely necessary. Here, P() is for wait and V() is for signal.
This is also called writers-preference.
A solution to the writers-preference scenario is presented below:
int readcount, writecount; (initial value = 0)
semaphore mutex_1, mutex_2, mutex_3, w, r ; (initial value = 1)
READER
P(mutex_3);
P(r);
16
P(mutex_1);
readcount := readcount + 1;
if readcount = 1 then P(w);
V(mutex_1);
V(r);
V(mutex_3);
reading is performed
P(mutex_1);
readcount := readcount - 1;
if readcount = 0 then V(w);
V(mutex_1);
WRITER
P(mutex_2);
writecount := writecount + 1;
if writecount = 1 then P(r);
V(mutex_2);
P(w);
writing is performed
V(w);
P(mutex_2);
writecount := writecount - 1;
if writecount = 0 then V(r);
V(mutex_2);
The third readers-writers problem
In fact, the solutions implied by both problem statements result in starvation — the first readers-writers
problem may starve writers in the queue, and the second readers-writers problem may starve readers.
Therefore, the third readers-writers problem is sometimes proposed, which adds the constraint that no
thread shall be allowed to starve; that is, the operation of obtaining a lock on the shared data will always
terminate in a bounded amount of time.
A solution with fairness for both readers and writers might be as follows:
semaphores: no_waiting, no_accessing, counter_mutex ( initial value
is 1 )
shared variables: nreaders ( initial value is 0 )
local variables: prev, current
WRITER:
17
P( no_waiting );
P( no_accessing );
V( no_waiting );
... write ...
V( no_accessing );
READER:
P( no_waiting );
P( counter_mutex );
prev := nreaders;
nreaders := nreaders + 1;
V( counter_mutex );
if prev = 0 then P( no_accessing );
V( no_waiting );
... read ...
P( counter_mutex );
nreaders := nreaders - 1;
current := nreaders;
V( counter_mutex );
if current = 0 then V( no_accessing );
3) Dining Philosopher problem
The "Dining Philosophers", a classic problem involving concurrency and shared
resources
18
Critical Section Problem
Critical Section
The key to preventing trouble involving shared storage is find some way to prohibit
more than one process from reading and writing the shared data simultaneously. That
part of the program where the shared memory is accessed is called the Critical
Section. To avoid race conditions and flawed results, one must identify codes
inCritical Sections in each thread. The characteristic properties of the code that form
a Critical Section are




Codes that reference one or more variables in a “read-update-write” fashion
while any of those variables is possibly being altered by another thread.
Codes that alter one or more variables that are possibly being referenced in
“read-updata-write” fashion by another thread.
Codes use a data structure while any part of it is possibly being altered by
another thread.
Codes alter any part of a data structure while it is possibly in use by another
thread.
Here, the important point is that when one process is executing shared modifiable data
in its critical section, no other process is to be allowed to execute in its critical section.
Thus, the execution of critical sections by the processes is mutually exclusive in time.
19
synchronization mechanismmutex :
semaphores:
monitors:
condition variables:
critical regions:
read write locks :
Process Scheduling
CPU scheduling is the basis of multi programmed operating system. By switching the CPU among
processes, the operating system can make the computer more productive.
The successes of CPU scheduling depends on an observed property of processes: processes execution
consists of a cycle pf cpu execution & I/O wait. Processes alternate between these two states: processes
execution begins with a CPU burst , That is followed by an I/O burst , which is followed by another CPU
burst , then another I/O burst and so on.
Scheduling Criteria : Many criteria have been suggested for comparing CPU scheduling
algorithm. Which characteristics are used for comparing can make a substantial difference in
which algorithm is judged to be best. The criteria include the following :
CPU utilization : CPU utilization can range from o to 100 percent. It real system , it should
range from 40 percent to 90 percent.
Through put: one measure of work is the no. of processes that are completed per time unit
called throughput.
20
Turnaround time: the interval from the time of submission of a process to the time of
completion is the turnaround.
Waiting time: waiting time is the sum of the periods spend waiting in the ready queue.
Response time: a process can produce same O/P fairly early and can continue computing
new results. While previous results are being O/P to the user. Thus , another measure is the
time from the submission of a request until the first response is produced. This measure called
response time.
Types of scheduling
In many multitasking systems the processor scheduling subsystem operates on three levels,
differentiated by the time scale at which they perform their operations. In this sense we
differentiate among:



Long term scheduling: which determines which programs are admitted to the system for
execution and when, and which ones should be exited.
Medium term scheduling: which determines when processes are to be suspended and
resumed;
Short term scheduling (or dispatching): which determines which of the ready processes
can have CPU resources, and for how long.
Non-Preemptive Vs Preemptive Scheduling

Non-Preemptive: Non-preemptive algorithms are designed so that once a process enters the
running state(is allowed a process), it is not removed from the processor until it has completed its
service time ( or it explicitly yields the processor).
context_switch() is called only when the process terminates or blocks.

Preemptive: Preemptive algorithms are driven by the notion of prioritized computation. The
process with the highest priority should always be the one currently using the processor. If a
process is currently using the processor and a new process with a higher priority enters, the
ready list, the process on the processor should be removed and returned to the ready list until it is
once again the highest-priority process in the system.
context_switch() is called even when the process is running usually done via a timer interrupt
Schedulling Algorithms
First In First Out (FIFO)
This is a Non-Premptive scheduling algorithm. FIFO strategy assigns priority to processes in the
order in which they request the processor.The process that requests the CPU first is allocated
21
the CPU first.When a process comes in, add its PCB to the tail of ready queue. When running
process terminates, dequeue the process (PCB) at head of ready queue and run it.
Consider the example with P1=24, P2=3, P3=3
Gantt Chart for FCFS : 0 - 24 P1 , 25 - 27 P2 , 28 - 30 P3
Turnaround time for P1 = 24
Turnaround time for P1 = 24 + 3
Turnaround time for P1 = 24 + 3 + 3
Average Turnaround time = (24*3 + 3*2 + 3*1) / 3
In general we have (n*a + (n-1)*b + ....) / n
If we want to minimize this, a should be the smallest, followed by b and
so on.
Comments: While the FIFO algorithm is easy to implement, it ignores the service time
request and all other criteria that may influence the performance with respect to
turnaround or waiting time.
Problem: One Process can monopolize CPU
Solution: Limit the amount of time a process can run without a context switch. This time
is called a time slice.
Round Robin
Round Robin calls for the distribution of the processing time equitably among all processes requesting the
processor.Run process for one time slice, then move to back of queue. Each process gets equal share of
the CPU. Most systems use some variant of this.
Choosing Time Slice
What happens if the time slice isnt chosen carefully?

For example, consider two processes, one doing 1 ms computation followed by 10 ms I/O, the
other doing all computation. Suppose we use 20 ms time slice and round-robin scheduling: I/O
process runs at 11/21 speed, I/O devices are only utilized 10/21 of time.
22

Suppose we use 1 ms time slice: then compute-bound process gets interrupted 9 times
unnecessarily before I/O-bound process is runnable
Problem: Round robin assumes that all processes are equally important; each receives an equal portion
of the CPU. This sometimes produces bad results. Consider three processes that start at the same time
and each requires three time slices to finish. Using FIFO how long does it take the average job to
complete (what is the average response time)? How about using round robin?
* Process A finishes after 3 slices, B 6, and C 9. The average is (3+6+9)/3 = 6 slices.
* Process A finishes after 7 slices, B 8, and C 9, so the average is (7+8+9)/3 = 8 slices.
Round Robin is fair, but uniformly enefficient.
Solution: Introduce priority based scheduling.
Priority Based Scheduling
Run highest-priority processes first, use round-robin among processes of equal priority. Re-insert process
in run queue behind all processes of greater or equal priority.

Allows CPU to be given preferentially to important processes.
23

Scheduler adjusts dispatcher priorities to achieve the desired overall priorities for the processes,
e.g. one process gets 90% of the CPU.
Comments: In priority scheduling, processes are allocated to the CPU on the basis of an externally
assigned priority. The key to the performance of priority scheduling is in choosing priorities for the
processes.
Problem: Priority scheduling may cause low-priority processes to starve
Solution: (AGING) This starvation can be compensated for if the priorities are internally computed.
Suppose one parameter in the priority assignment function is the amount of time the process has been
waiting. The longer a process waits, the higher its priority becomes. This strategy tends to eliminate the
starvation problem.
Shortest Job First
Maintain the Ready queue in order of increasing job lengths. When a job comes in, insert it in the ready
queue based on its length. When current process is done, pick the one at the head of the queue and run
it.
This is provably the most optimal in terms of turnaround/response time.
But, how do we find the length of a job?
Make an estimate based on the past behavior.
Say the estimated time (burst) for a process is E0, suppose the actual
time is measured to be T0.
Update the estimate by taking a weighted sum of these two
ie. E1 = aT0 + (1-a)E0
in general, E(n+1) = aTn + (1-a)En
(Exponential average)
if a=0, recent history no weightage
if a=1, past history no weightage.
typically a=1/2.
E(n+1) = aTn + (1-a)aTn-1 + (1-a)^jatn-j + ...
Older information has less weightage
Comments: SJF is proven optimal only when all jobs are available simultaneously.
Problem: SJF minimizes the average wait time because it services small processes before it services
large ones. While it minimizes average wiat time, it may penalize processes with high service time
requests. If the ready list is saturated, then processes with large service times tend to be left in the ready
list while small processes receive service. In extreme case, where the system has little idle time,
processes with large service times will never be served. This total starvation of large processes may be a
serious liability of this algorithm.
24
Solution: Multi-Level Feedback Queques
Multi-Level Feedback Queue
Several queues arranged in some priority order.
Each queue could have a different scheduling discipline/ time quantum.
Lower quanta for higher priorities generally.
Defined by:




# of queues
scheduling algo for each queue
when to upgrade a priority
when to demote
Attacks both efficiency and response time problems.



Give newly runnable process a high priority and a very short time slice. If process uses up the
time slice without blocking then decrease priority by 1 and double its next time slice.
Often implemented by having a separate queue for each priority.
How are priorities raised? By 1 if it doesn't use time slice? What happens to a process that does
a lot of computation when it starts, then waits for user input? Need to boost priority a lot, quickly.
Remote procedure calls
Paging
Trashing
Trashing is high page fault situation. Trashing spends most of the time in swapping pages than
executing.
25
If the process does not have ―enough‖ frames then it wll quickly page fault, at that point ,
process will replace some pages, if pages are in active use then it will replace another pages
again and again
Multi-Processor Scheduling
Download