NOTES_CA403_OperatingSystem_sybbaca-converted-1
NOTES_CA403_OperatingSystem_sybbaca-converted-1
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
UNIT 1 : Introduction to OS
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
Services Provided by OS :
An operating system provides an environment for the execution of the program. It provides some services to the
programs.
The various services provided by an operating system are as follows:
• Program Execution: The system must be able to load a program into memory and to run that program. The
program must be able to terminate this execution either normally or abnormally.
• I/O Operation: A running program may require I/O. This I/O may involve a file or a I/O device for specific
device. Some special function can be desired. Therefore the operating system must provide a means to do I/O.
• File System Manipulation: The programs need to create and delete files by name and read and write files.
Therefore the operating system must maintain each and every files correctly.
• Communication: The communication is implemented via shared memory or by the technique of message passing
in which packets of information are moved between the processes by the operating system.
• Error detection: The operating system should take the appropriate actions for the occurrences of any type like
arithmetic overflow, access to the illegal memory location and too large user CPU time. • Research Allocation:
When multiple users are logged on to the system the resources must be allocated to each of them. For current
distribution of the resource among the various processes the operating system uses the CPU scheduling run times
which determine which process will be allocated with the resource. • Accounting: The operating system keep track
of which users use how many and which kind of computer resources. • Protection: The operating system is
responsible for both hardware as well as software protection. The operating system protects the information stored
in a multiuser computer system.
Types of OS :
Operating systems are there from the very first computer generation and they keep evolving with time. In this
chapter, we will discuss some of the important types of operating systems which are most commonly used.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
The users of a batch operating system do not interact with the computer directly. Each user prepares his job on an
off-line device like punch cards and submits it to the computer operator. To speed up processing, jobs with
similar needs are batched together and run as a group. The programmers leave their programs with the operator
and the operator then sorts the programs with similar requirements into batches.
• CPU is often idle, because the speed of the mechanical I/O devices is slower than the CPU.
Time-sharing is a technique which enables many people, located at various terminals, to use a particular computer
system at the same time. Time-sharing or multitasking is a logical extension of multiprogramming. Processor's
time which is shared among multiple users simultaneously is termed as time-sharing.
The main difference between Multiprogrammed Batch Systems and Time-Sharing Systems is that in case of
Multiprogrammed batch systems, the objective is to maximize processor use, whereas in Time-Sharing Systems,
the objective is to minimize response time.
Multiple jobs are executed by the CPU by switching between them, but the switches occur so frequently. Thus,
the user can receive an immediate response. For example, in a transaction processing, the processor executes each
user program in a short burst or quantum of computation. That is, if n users are present, then each user can get a
time quantum. When the user submits the command, the response time is in few seconds at most.
The operating system uses CPU scheduling and multiprogramming to provide each user with a small portion of a
time. Computer systems that were designed primarily as batch systems have been modified to time-sharing
systems.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
• Problem of reliability.
Distributed systems use multiple central processors to serve multiple real-time applications and multiple users.
Data processing jobs are distributed among the processors accordingly.
The processors communicate with one another through various communication lines (such as high-speed buses or
telephone lines). These are referred as loosely coupled systems or distributed systems. Processors in a distributed
system may vary in size and function. These processors are referred as sites, nodes, computers, and so on.
• With resource sharing facility, a user at one site may be able to use the resources available at another.
• Speedup the exchange of data with one another via electronic mail.
• If one site fails in a distributed system, the remaining sites can potentially continue operating.
A Network Operating System runs on a server and provides the server the capability to manage data, users,
groups, security, applications, and other networking functions. The primary purpose of the network operating
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
system is to allow shared file and printer access among multiple computers in a network, typically a local area
network (LAN), a private network or to other networks.
Examples of network operating systems include Microsoft Windows Server 2003, Microsoft Windows Server
2008, UNIX, Linux, Mac OS X, Novell NetWare, and BSD.
• Upgrades to new technologies and hardware can be easily integrated into the system.
• Remote access to servers is possible from different locations and types of systems.
A real-time system is defined as a data processing system in which the time interval required to process and
respond to inputs is so small that it controls the environment. The time taken by the system to respond to an input
and display of required updated information is termed as the response time. So in this method, the response time
is very less as compared to online processing.
Real-time systems are used when there are rigid time requirements on the operation of a processor or the flow of
data and real-time systems can be used as a control device in a dedicated application. A real-time operating
system must have well-defined, fixed time constraints, otherwise the system will fail. For example, Scientific
experiments, medical imaging systems, industrial control systems, weapon systems, robots, air traffic control
systems, etc.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
Hard real-time systems guarantee that critical tasks complete on time. In hard real-time systems, secondary
storage is limited or missing and the data is stored in ROM. In these systems, virtual memory is almost never
found.
Soft real-time systems are less restrictive. A critical real-time task gets priority over other tasks and retains the
priority until it completes. Soft real-time systems have limited utility than hard real-time systems. For example,
multimedia, virtual reality, Advanced Scientific Projects like undersea exploration and planetary rovers, etc.
OS Structure :
An operating system is a construct that allows the user application programs to interact with the system hardware.
Since the operating system is such a complex structure, it should be created with utmost care so it can be used and
modified easily. An easy way to do this is to create the operating system in parts. Each of these parts should be
well defined with clear inputs, outputs and functions.
Simple Structure
There are many operating systems that have a rather simple structure. These started as small systems and rapidly
expanded much further than their scope. A common example of this is MS-DOS. It was designed simply for a
niche amount for people. There was no indication that it would become so popular.
It is better that operating systems have a modular structure, unlike MS-DOS. That would lead to greater control
over the computer system and its various applications. The modular structure would also allow the programmers to
hide information as required and implement internal routines as they see fit without changing the outer
specifications.
Layered Structure
One way to achieve modularity in the operating system is the layered approach. In this, the bottom layer is the
hardware and the topmost layer is the user interface.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
As seen from the image, each upper layer is built on the bottom layer. All the layers hide some structures,
operations etc from their upper layers.
One problem with the layered structure is that each layer needs to be carefully defined. This is necessary because
the upper layers can only use the functionalities of the layers below them.
1. Microkernels
This structures the operating system by removing all nonessential portions of the kernel and implementing them as
system and user level programs.
• Generally they provide minimal process and memory management, and a communications facility.
• Communication between components of the OS is provided by message passing.
Main disadvantage is poor performance due to increased system overhead from message passing.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
Explain the different States of Process with example. OR Describe about the Life Cycle of a Process.
Ans.: Process States : The various stages through which a process passes is called its Life Cycle and this Life
Cycle of a process can be divided in to several stages called as “Process States”. When a process starts execution,
it goes through one state to another state.
Each process may be in one of the following states : (i) New (ii) Ready (iii) Running (iv) Waiting (v) Terminated
New: The process is being created.
• Ready: The process is waiting to be assigned to a processor.
• Running: Instructions are being executed.
• Waiting: The process is waiting for some event to occur.
• Terminated: The process has finished execution.
Explain the Process Control Block (PCB) with diagram.
Ans.: Process Control Block (PCB) : To control the various processes the Operating System maintains a table
called the Process Table. The Process Table contains one entry per process. These entries are referred to as
“Process Control Block”. It contains many pieces of information related with a specific process including the
Process Number, Process State, Program Counter, CPU Registers, CPU Scheduling Information, Memory
Management Information, Accounting Informa tion, and I/O Status Information.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
Ans.: The Scheduling Queues in the Systems are : (1) Job Queue : As processes enters in the System, they are put
into a job queue. (2) Ready Queue : The processes that are residing in the main memory and are ready and waiting
to execute are kept in the ready queue. (3) Device Queue : This queue contains a list of processes waiting for I/O
devices.
Write about the different types of Schedulers.
Ans.: Types of schedulers : There are basically three types of schedulers :
(1) Long Term Scheduler : This Scheduler determines which job will be submitted for immediate processing. It
selects from the job pool and loads them into memory.
(2) Short Term Scheduler : It is also called a CPU Scheduler. It allocates processes belonging to ready queue to
CPU for immediate processing.
(3) Medium Term Scheduler : It is also called as Memory Scheduler. During the execution processes are swapped-
out and swapped-in by the Medium Term Scheduler
Context Switch
Context Switch When CPU switches to another process, the system must save the state of the old process and load
the saved state for the new process via a context switch Context of a process represented in the PCB Context-
switch time is overhead; the system does no useful work while switching Time dependent on hardware support
Process Creation
Parent process create children processes, which, in turn create other processes, forming a tree of processes
Generally, process identified and managed via a process identifier (pid) Resource sharing Parent and children
share all resources Children share subset of parent’s resources Parent and child share no resources Execution
Parent and children execute concurrently Parent waits until children terminate Address space Child duplicate of
parent Child has a program loaded into it UNIX examples fork system call creates new process exec system call
used after a fork to replace the process’ memory space with a new program
Process Termination
Process executes last statement and asks the operating system to delete it (exit) Output data from child to parent
(via wait) Process’ resources are deallocated by operating system Parent may terminate execution of children
processes (abort) Child has exceeded allocated resources Task assigned to child is no longer required If parent is
exiting Some operating system do not allow child to continue if its parent terminates All children terminated -
cascading termination
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
Interprocess Communication
Processes within a system may be independent or cooperating Cooperating process can affect or be affected by
other processes, including sharing data Reasons for cooperating processes: Information sharing Computation
speedup Modularity Convenience Cooperating processes need interprocess communication (IPC) Two models of
IPC Shared memory Message passing
Interprocess Communication –
Message Passing Mechanism for processes to communicate and to synchronize their actions Message system –
processes communicate with each other without resorting to shared variables IPC facility provides two operations:
send(message) – message size fixed or variable receive(message) If P and Q wish to communicate, they need to:
establish a communication link between them exchange messages via send/receive Implementation of
communication link physical (e.g., shared memory, hardware bus) logical (e.g., logical properties)
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
Turnaround Time: Turnaround time is an amount of time to execute a specific process. It is the calculation of the
total time spent waiting to get into the memory, waiting in the queue and, executing on the CPU. The period
between the time of process submission to the completion time is the turnaround time.
Interval Timer
Timer interruption is a method that is closely related to preemption. When a certain process gets the CPU
allocation, a timer may be set to a specified interval. Both timer interruption and preemption force a process to
return the CPU before its CPU burst is complete.
Most of the multi-programmed operating system uses some form of a timer to prevent a process from tying up the
system forever.
What is Dispatcher?
It is a module that provides control of the CPU to the process. The Dispatcher should be fast so that it can run on
every context switch. Dispatch latency is the amount of time needed by the CPU scheduler to stop one process and
start another.
Functions performed by Dispatcher:
• Context Switching
• Switching to user mode
• Moving to the correct location in the newly loaded program.
Scheduling Algorithms
To decide which process to execute first and which process to execute last to achieve maximum CPU utilization,
computer scientists have defined some algorithms, they are:
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
• First Come First Serve, is just like FIFO(First in First out) Queue data structure, where the data element
which is added to the queue first, is the one who leaves the queue first.
• It's easy to understand and implement programmatically, using a Queue data structure, where a new
process enters through the tail of the queue, and the scheduler selects process from the head of the queue.
• A perfect real life example of FCFS scheduling is buying tickets at ticket counter.
For every scheduling algorithm, Average waiting time is a crucial parameter to judge it's performance.
AWT or Average waiting time is the average of the waiting times of the processes in the queue, waiting for the
scheduler to pick them for execution.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
For the above given proccesses, first P1 will be provided with the CPU resources,
• Similarly, waiting time for process P3 will be execution time of P1 + execution time for P2, which will
be (21 + 3) ms = 24 ms.
• For process P4 it will be the sum of execution times of P1, P2 and P3.
The GANTT chart above perfectly represents the waiting time for each process.
Below we have a few shortcomings or problems with the FCFS scheduling algorithm:
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
1. It is Non Pre-emptive algorithm, which means the process priority doesn't matter.
If a process with very least priority is being executed, more like daily routine backup process, which
takes more time, and all of a sudden some other high priority process arrives, like interrupt to avoid
system crash, the high priority process will have to wait, and hence in this case, the system will crash, just
because of improper process scheduling.
3. Resources utilization in parallel is not possible, which leads to Convoy Effect, and hence poor
resource(CPU, I/O etc) utilization.
• It is of two types:
1. Non Pre-emptive
2. Pre-emptive
• To successfully implement it, the burst time/duration time of the processes should be known to the
processor in advance, which is practically not feasible all the time.
• This scheduling algorithm is optimal if all the jobs/processes are available at the same time. (either Arrival
time is 0 for all, or Arrival time is same for all)
Consider the below processes available in the ready queue for execution, with arrival time as 0 for all and
given burst times.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
As you can see in the GANTT chart above, the process P4 will be picked up first as it has the shortest burst time,
then P2, followed by P3 and at last P1.
We scheduled the same set of processes using the First come first serve algorithm in the previous tutorial, and got
average waiting time to be 18.75 ms, whereas with SJF, the average waiting time comes out 4.5 ms.
If the arrival time for processes are different, which means all the processes are not available in the ready queue
at time 0, and some jobs arrive after some time, in such situation, sometimes process with short burst time have to
wait for the current process's execution to finish, because in Non Pre-emptive SJF, on arrival of a process with
short duration, the existing job/process's execution is not halted/stopped to execute the short job first.
This leads to the problem of Starvation, where a shorter process has to wait for a long time until the current
longer process gets executed. This happens if shorter jobs keep coming, but this can be solved using the concept
of aging.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
In Preemptive Shortest Job First Scheduling, jobs are put into ready queue as they arrive, but as a process
with short burst time arrives, the existing process is preempted or removed from execution, and the shorter job is
executed first.
The average waiting time for preemptive shortest job first scheduling is less than both,non preemptive SJF
scheduling and FCFS scheduling
As you can see in the GANTT chart above, as P1 arrives first, hence it's execution starts immediately, but just
after 1 ms, process P2 arrives with a burst time of 3 ms which is less than the burst time of P1, hence the
process P1(1 ms done, 20 ms left) is preemptied and process P2 is executed.
As P2 is getting executed, after 1 ms, P3 arrives, but it has a burst time greater than that of P2, hence execution
of P2 continues. But after another millisecond, P4 arrives with a burst time of 2 ms, as a result P2(2 ms done, 1 ms
left) is preemptied and P4 is executed.
After the completion of P4, process P2 is picked up and finishes, then P2 will get executed and at last P1.
The Pre-emptive SJF is also known as Shortest Remaining Time First, because at any given point of time, the
job with the shortest remaining time is executed first.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
In the Shortest Job First scheduling algorithm, the priority of a process is generally the inverse of the CPU burst
time, i.e. the larger the burst time the lower is the priority of that process.
In case of priority scheduling the priority is not always set as the inverse of the CPU burst time, rather it can be
internally or externally set, but yes the scheduling is done on the basis of priority of the process where the process
which is most urgent is processed first, followed by the ones with lesser priority in order.
The priority of process, when internally defined, can be decided based on memory requirements, time
limits ,number of open files, ratio of I/O burst to CPU burst etc.
Whereas, external priorities are set based on criteria outside the operating system, like the importance of the
process, funds paid for the computer resource use, makrte factor etc.
1. Preemptive Priority Scheduling: If the new process arrived at the ready queue has a higher priority than
the currently running process, the CPU is preempted, which means the processing of the current process is
stoped and the incoming new process with higher priority gets the CPU for its execution.
Consider the below table fo processes with their respective CPU burst times and the priorities.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
As you can see in the GANTT chart that the processes are given CPU time just on the basis of the priorities.
A process is considered blocked when it is ready to run but has to wait for the CPU as some other process is
running currently.
But in case of priority scheduling if new higher priority processes keeps coming in the ready queue then the
processes waiting in the ready queue with lower priority may have to wait for long durations before getting the
CPU for execution.
In 1973, when the IBM 7904 machine was shut down at MIT, a low-priority process was found which was
submitted in 1967 and had not yet been run.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
To prevent starvation of any process, we can use the concept of aging where we keep on increasing the priority of
low-priority process based on the its waiting time.
For example, if we decide the aging factor to be 0.5 for each day of waiting, then if a process with
priority 20(which is comparitively low priority) comes in the ready queue. After one day of waiting, its priority is
increased to 19.5 and so on.
Doing so, we can ensure that no process will have to wait for indefinite time for getting CPU time for processing.
1. Round Robin Scheduling algorithm resides under the category of Preemptive Algorithms.
2. This algorithm is one of the oldest, easiest, and fairest algorithm.
3. This Algorithm is a real-time algorithm because it responds to the event within a specific time limit.
4. In this algorithm, the time slice should be the minimum that is assigned to a specific task that needs to be
processed. Though it may vary for different operating systems.
5. This is a hybrid model and is clock-driven in nature.
6. This is a widely used scheduling method in the traditional operating system.
Important terms
1. Completion Time It is the time at which any process completes its execution.
2. Turn Around Time This mainly indicates the time Difference between completion time and arrival time.
The Formula to calculate the same is: Turn Around Time = Completion Time – Arrival Time
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
3. Waiting Time(W.T): It Indicates the time Difference between turn around time and burst time. And is
calculated as Waiting Time = Turn Around Time – Burst Time
In the above diagram, arrival time is not mentioned so it is taken as 0 for all processes.
Note: If arrival time is not given for any problem statement then it is taken as 0 for all processes; if it is given then
the problem can be solved accordingly.
Explanation
The value of time quantum in the above example is 5.Let us now calculate the Turn around time and waiting time
for the above example :
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
P1 21 32-0=32 32-21=11
P2 3 8-0=8 8-3=5
P3 6 21-0=21 21-6=15
P4 2 15-0=15 15-2=13
Average waiting time is calculated by adding the waiting time of all processes and then dividing them by no.of
processes.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
For example, A common division is made between foreground(or interactive) processes and background (or
batch) processes. These two types of processes have different response-time requirements, and so might have
different scheduling needs. In addition, foreground processes may have priority over background processes.
A multi-level queue scheduling algorithm partitions the ready queue into several separate queues. The processes
are permanently assigned to one queue, generally based on some property of the process, such as memory size,
process priority, or process type. Each queue has its own scheduling algorithm.
For example, separate queues might be used for foreground and background processes. The foreground queue
might be scheduled by the Round Robin algorithm, while the background queue is scheduled by an FCFS
algorithm.
In addition, there must be scheduling among the queues, which is commonly implemented as fixed-priority
preemptive scheduling. For example, The foreground queue may have absolute priority over the background
queue.
1. System Processes
2. Interactive Processes
3. Interactive Editing Processes
4. Batch Processes
5. Student Processes
Each queue has absolute priority over lower-priority queues. No process in the batch queue, for example, could
run unless the queues for system processes, interactive processes, and interactive editing processes were all empty.
If an interactive editing process entered the ready queue while a batch process was running, the batch process will
be preempted.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
In this case, if there are no processes on the higher priority queue only then the processes on the low priority
queues will run. For Example: Once processes on the system queue, the Interactive queue, and Interactive editing
queue become empty, only then the processes on the batch queue will run.
• System Process The Operating system itself has its own process to run and is termed as System Process.
• Interactive Process The Interactive Process is a process in which there should be the same kind of
interaction (basically an online game ).
• Batch Processes Batch processing is basically a technique in the Operating system that collects the
programs and data together in the form of the batch before the processing starts.
• Student Process The system process always gets the highest priority while the student processes always
get the lowest priority.
In an operating system, there are many processes, in order to obtain the result we cannot put all processes in a
queue; thus this process is solved by Multilevel queue scheduling.
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
Multilevel feedback queue scheduling, however, allows a process to move between queues. The idea is to separate
processes with different CPU-burst characteristics. If a process uses too much CPU time, it will be moved to a
lower-priority queue. Similarly, a process that waits too long in a lower-priority queue may be moved to a higher-
priority queue. This form of aging prevents starvation.
The definition of a multilevel feedback queue scheduler makes it the most general CPU-scheduling algorithm. It
can be configured to match a specific system under design. Unfortunately, it also requires some means of selecting
values for all the parameters to define the best scheduler. Although a multilevel feedback queue is the most
general scheme, it is also the most complex.
Explanation:
First of all, Suppose that queues 1 and 2 follow round robin with time quantum 8 and 16 respectively and queue 3
follows FCFS. One of the implementations of Multilevel Feedback Queue Scheduling is as follows:
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)
2. In queue 1, the process executes for 8 unit and if it completes in these 8 units or it gives CPU for I/O
operation in these 8 units unit than the priority of this process does not change, and if for some reasons it
again comes in the ready queue than it again starts its execution in the Queue 1.
3. If a process that is in queue 1 does not complete in 8 units then its priority gets reduced and it gets shifted
to queue 2.
4. Above points 2 and 3 are also true for processes in queue 2 but the time quantum is 16 units. Generally, if
any process does not complete in a given time quantum then it gets shifted to the lower priority queue.
5. After that in the last queue, all processes are scheduled in an FCFS manner.
6. It is important to note that a process that is in a lower priority queue can only execute only when the higher
priority queues are empty.
7. Any running process in the lower priority queue can be interrupted by a process arriving in the higher
priority queue.
Also, the above implementation may differ for the example in which the last queue will follow Round-robin
Scheduling.
In the above Implementation, there is a problem and that is; Any process that is in the lower priority queue
has to suffer starvation due to some short processes that are taking all the CPU time.
And the solution to this problem is : There is a solution that is to boost the priority of all the process after regular
intervals then place all the processes in the highest priority queue.
Following are some points to understand the need for such complex scheduling:
Advantages of MFQS
Disadvantages of MFQS
Subject: Data Structure sub code: CA403( 2019 Pattern ) Class : S.Y. BBA(CA)