OS Unit 1 KCA - 203
OS Unit 1 KCA - 203
INTRODUCTION
1.1 WHAT IS AN OPERATING SYSTEM?
Operating System is a program that acts as an intermediary between a
user and computer hardware.
In a computer system, we find four main components: the hardware, the operating
system, the application software and the users. In a computer system the hardware
provides the basic computing resources. The applications programs define the way
in which these resources are used to solve the computing problems of the users.
The operating system controls and coordinates the use of the hardware among the
various systems programs and application programs for the various users.
1
OPERATING SYSTEM (KCA-203) Unit 1
The abstract view of the components of a computer system and the positioning of
OS is shown in the Figure 1.
2
OPERATING SYSTEM (KCA-203) Unit 1
Layered Structure
The operating system is split into various layers. In the layered operating system
and each of the layers have different functionalities. This type of operating system
was created as an improvement over the early monolithic systems.
Layering provides a distinct advantage in an operating system. All the layers can
be defined separately and interact with each other as required. Also, it is easier to
create, maintain and update the system if it is done in the form of layers. Change in
one layer specification does not affect the rest of the layers.
Each of the layers in the operating system can only interact with the layers that are
above and below it. The lowest layer handles the hardware and the uppermost layer
deals with the user applications.
3
OPERATING SYSTEM (KCA-203) Unit 1
There are six layers in the layered operating system. A diagram demonstrating
these layers is as follows:
Hardware
This layer interacts with the system hardware and coordinates with all the
peripheral devices used such as printer, mouse, keyboard, scanner etc. The
hardware layer is the lowest layer in the layered operating system architecture.
CPU Scheduling
This layer deals with scheduling the processes for the CPU. There are many
scheduling queues that are used to handle processes. When the processes enter the
system, they are put into the job queue. The processes that are ready to execute in
the main memory are kept in the ready queue.
Memory Management
4
OPERATING SYSTEM (KCA-203) Unit 1
Memory management deals with memory and the moving of processes from disk
to primary memory for execution and back again. This is handled by the third layer
of the operating system.
Process Management
This layer is responsible for managing the processes i.e assigning the processor to
a process at a time. This is known as process scheduling. The different algorithms
used for process scheduling are FCFS (first come first served), SJF (shortest job
first), priority scheduling, round-robin scheduling etc.
I/O Buffer
I/O devices are very important in the computer systems. They provide users with
the means of interacting with the system. This layer handles the buffers for the I/O
devices and makes sure that they work correctly.
User Programs
This is the highest layer in the layered operating system. This layer deals with the
many user programs and applications that run in an operating system such as word
processors, games, browsers etc.
The users who are using a batch operating system do not interact with the
computer directly. Each user prepares its job on an off-line device like punch cards
and submits it to the computer operator. An operator takes up similar jobs and
groups them together into a batch, and then these batches are executed one by one.
Advantages of Batch OS
5
OPERATING SYSTEM (KCA-203) Unit 1
Disadvantages of OS
• There is a lack of interaction between the user and the job.
• CPU is being often idle, because the speed of the mechanical I/O devices is
slower than the CPU.
• It is difficult to provide the desired priority.
Examples of Batch OS: payroll system, bank statements, data entry, etc.
Advantages
1. Each task gets an equal opportunity.
2. Fewer chances of duplication of software.
3. CPU idle time can be reduced.
Disadvantages
1. Reliability problem.
2. One must have to take of the security and integrity of user programs and data.
6
OPERATING SYSTEM (KCA-203) Unit 1
In a time-sharing operating system, the CPU time is divided into small time
intervals called time slices or quantum. Each user or process is allocated a time
slice during which it can execute its tasks. The operating system switches
between processes rapidly, giving the illusion of parallel execution.
The operating system uses scheduling algorithms, such as round-robin or
priority-based scheduling, to determine which process should be allocated the
CPU next. Context switching, which involves saving and restoring the execution
context of each process, is performed to switch between processes.
• Hard real-time OS
The hard real-time OS is the operating system for mainly the applications in
which the slightest delay is also unacceptable. The time constraints of such
applications are very strict. Such systems are built for life-saving equipment like
parachutes and airbags, which immediately need to be in action if an accident
happens.
• Soft real-time OS
The soft real-time OS is the operating system for applications where time
constraint is not very strict.
In a soft real-time system, an important task is prioritized over less important
tasks, and this priority remains active until the completion of the task.
Furthermore, a time limit is always set for a specific job, enabling short time
delays for future tasks, which is acceptable.
For Example, virtual reality, reservation systems, etc.
Advantages of Real-Time OS
7
OPERATING SYSTEM (KCA-203) Unit 1
Disadvantages of Real-Time OS
8
OPERATING SYSTEM (KCA-203) Unit 1
9
OPERATING SYSTEM (KCA-203) Unit 1
Time-sliced system: It is the system where each user talk is allocated to a short
span of cpu time. A small time duration is allotted to every task. CPU time is
divided into small time slices, and one time is assigned to each other. The
decision to run the next piece of the job is decided by the schedule. This
schedule executes the run instructions that need to be executed. The user can
take turns and thus the operating system will handle the user’s request among the
users who are connected. This feature is not applicable in the single-user
operating system. They use the mainframe system concurrently.
Example: Mainframe, a partial exam of the time-sliced system.
10
OPERATING SYSTEM (KCA-203) Unit 1
Advantages:
• It helps in the sharing of data and information among different users.
• It also helps in the sharing of hardware resources such as printers.
• It avoids disruption if any one computer fails it does not affect any other
computer present on that network.
• Users can share their work with other users.
• The multi-user operating system is very helpful in economic improvement.
• Backing up data can be done in the multi-user operating system.
• The services of the multi-user operating systems are very stable and
systematic.
Disadvantages:
• It requires expensive hardware to set up a mainframe computer
• When multiple users log on or work on the same system it reduces the
overall performance of the system.
• Information is shared with the public so privacy becomes a concern here.
11
OPERATING SYSTEM (KCA-203) Unit 1
Early operating system could execute various programs at the same time, although
multitasking was not fully supported. As a result, a single software could consume
the entire CPU of the computer while completing a certain activity. Basic operating
system functions, such as file copying, prevented the user from completing other
tasks, such as opening and closing windows. Fortunately, because modern
operating systems have complete multitasking capability, numerous programs can
run concurrently without interfering with one other. In addition, many operating
system processes can run at the same time.
Types of Multitasking
There are mainly two types of multitasking. These are as follows:
1. Preemptive Multitasking
2. Cooperative Multitasking
Preemptive Multitasking
Preemptive multitasking is a special task assigned to a computer operating system.
It decides how much time one task spends before assigning another task to use the
operating system. Because the operating system controls the entire process, it is
referred to as 'preemptive'.
Cooperative Multitasking
The term 'Non-Preemptive Multitasking' refers to cooperative multitasking. The
main purpose of cooperative multitasking is to run the present task while releasing
the CPU to allow another process to run.
Windows and MacOS used cooperative multitasking. A Windows program will
respond to a message by performing some short unit of work before handing the
CPU over to the operating system until the program receives another message. It
worked perfectly as long as all programs were written with other programs in mind
and bug-free.
Advantage of Multitasking
• Manage Several Users
This operating system is more suited to supporting multiple users simultaneously,
and multiple apps can run smoothly without interfering with system performance.
• Virtual Memory
The greatest virtual memory system is found in multitasking operating systems.
Because of virtual memory, any program does not require a long wait time to
complete its tasks; if this problem arises, those programs are moved to virtual
memory.
• Good Reliability
12
OPERATING SYSTEM (KCA-203) Unit 1
Multitasking operating systems give more flexibility to several users, and they are
happier as a result. On which each user can execute single or multiple programs
simultaneously.
• Secured Memory
The multitasking operating systems have well-defined memory management. Due
to this operating system does not allow any types of permissions for undesirable
programs to waste memory.
• Time Shareable
All tasks are allotted a specified amount of time so that they do not have to wait for
the CPU.
• Background Processing
A multitasking operating system provides a better environment for background
processes to run. These background programs are not visible to most users, but
they help other programs like firewalls, antivirus software, and others run well.
• Optimize the computer resources
A multitasking operating system may manage various computer resources like I/O
devices, RAM, hard disk, CPU, and others.
• Use Several Programs
Users can run many programs simultaneously, like an internet browser, games, MS
Excel, PowerPoint, and other utilities.
Disadvantages
Various disadvantages of multitasking are as follows:
• Processor Boundation
The system may run programs slowly because of the poor speed of their
processors, and their reaction time might rise when processing many programs. To
solve this problem, more processing power is required.
• Memory Boundation
The computer's performance may get slow performance due to the multiple
programs run at the same time because the main memory gets overloaded while
loading multiple programs. Because the CPU is unable to provide different times
for each program, reaction time increases. The primary cause of this issue is that it
makes use of low-capacity RAM. As a result, the RAM capacity can be raised to
provide a solution.
• CPU Heat Up
The multiple processors are busier at the same time to complete any task in a
multitasking environment, so the CPU generates more heat.
13
OPERATING SYSTEM (KCA-203) Unit 1
14
OPERATING SYSTEM (KCA-203) Unit 1
Advantages of Multithreading
• Improves execution speed (by combining CPU machine and I/O wait
times).
• Multithreading can be used to achieve concurrency.
• Reduces the amount of time it takes for context switching.
• Improves responsiveness.
• Make synchronous processing possible (separates the execution of
independent threads).
• Increases throughput.
• Performs foreground and background work in parallel.
Disadvantages of Multithreading
• Because the threads share the same address space and may access resources
such as open files, difficulties might arise in managing threads if they
utilize incompatible data structures.
• If we don't optimize the number of threads, instead of gaining performance,
we may lose performance.
• If a parent process requires several threads to function properly, the child
processes should be multithreaded as well, as they may all be required.
15
OPERATING SYSTEM (KCA-203) Unit 1
Program Execution
Several tasks must be completed in order to run a programme. Both the data and
instructions must be loaded into the main memory. Furthermore, files and input-
output devices should be initialized, as well as other resources that have to be
prepared. These types of jobs are handled by the operating structures. The user no
longer has to be concerned about memory allocation, multitasking, or anything
else.
Program Creation
The operating system provides structures and tools, like editors and debuggers, to
aid programmers in the creation, modification, and debugging of programs.
16
OPERATING SYSTEM (KCA-203) Unit 1
Errors can happen frequently when working with computers. Errors can occur in
the following areas:
• Memory hardware: For example, the memory becomes full, memory error,
etc.
• User program: For example, attempting to access illegal locations of
memory, dividing by zero, using too much CPU time, and many more.
• Input/ Output devices: For example, a network having a connection failure,
the lack of paper in a printer, and many more.
The operating system would take appropriate action and create messages to
guarantee correct and consistent computation in the face of these and other types of
probable mistakes.
Accounting
To improve overall performance, an operating device collects utilisation records
for a variety of assets and tracks overall performance metrics and responsive time.
These personal records are useful for future upgrades and device adjustments to
improve overall performance.
For example,
When a user downloads software from the internet, that programme could contain
malicious code that harms other programs. While downloading such programs, the
operating system guarantees that suitable checks are performed.
File Management
17
OPERATING SYSTEM (KCA-203) Unit 1
Secondary storage devices, such as magnetic tapes, magnetic disks and optical
disks, are used by computers to store data and information. Speed, data transfer
rate, capacity, and data access techniques are all characteristics of storage media.
The OS must be aware of the many types of files as well as the properties of
various storage devices in order to manage them. It must also provide the
proportion and security method for papers.
Communication
The operating system is in charge of coordinating the transfer of data and programs
across computers connected by a network. Message passing and shared memory
are used to accomplish this communication.
What is Kernel?
18
OPERATING SYSTEM (KCA-203) Unit 1
Types of Kernel
1. Monolithic Kernels
It means, in this type of kernel, there is no different memory used for user services
and kernel services.
As it uses the same memory space, the size of the kernel increases, increasing the
overall size of the OS.
19
OPERATING SYSTEM (KCA-203) Unit 1
The execution of processes is also faster than other kernel types as it does not use
separate user and kernel space.
Examples of Monolithic Kernels are Unix, Linux, Open VMS, XTS-400, etc.
Advantages:
Disadvantages:
o If any service generates any error, it may crash down the whole system.
o These kernels are not portable, which means for each new architecture, they
must be rewritten.
o Large in size and hence become difficult to manage.
o To add a new service, the complete operating system needs to be modified.
2. Microkernel
20
OPERATING SYSTEM (KCA-203) Unit 1
These kernels use a message passing system for handling the request from one
server to another server.
Advantages
Disadvantages
Reentrant Kernel
Reentrant Kernel: In kernel mode, a reentrant kernel allows processes (or, more
precisely, their corresponding kernel threads) to give up the CPU. They have no
21
OPERATING SYSTEM (KCA-203) Unit 1
effect on other processes entering kernel mode. Multiple processor systems may
be scheduled together in the case of single-processor systems.
Example:
A disc read is an example of this. When a user program requests a disc read, the
scheduler will delegate the CPU to another process (kernel thread) until the disc
controller issues an interrupt indicating that the data is accessible and our thread
can be resumed. This process can still access I/O, such as user input, which
requires kernel functions. The system remains responsive, and the amount of
CPU time wasted as a result of IO delays is reduced. The original function
(whatever requested data) would be blocked in a non-reentrant kernel until the
disc read was completed.
If a computer program or routine can be safely called again before its previous
invocation has been completed, it is said to be reentrant (i.e it can be safely
executed concurrently). A computer program or routine that is reentrant:
• There cannot be any non-constant data that is static (or global).
• The address must not be returned to static (or global) non-constant data.
• It must only work with the data provided by the caller.
• Locks should not be used to protect singleton resources, a variable that
is only referenced once
• It must not change its own code (unless executing in its own unique
thread storage).
• Non-reentrant computer programs or routines must not be called.
Non-reentrant functions can still be executed by reentrant kernels if locks are
used to ensure that only one process can run the non-reentrant function. Even
though the current process is operating in kernel mode, hardware interrupts can
suspend it (allowing things like Ctrl+c to cease execution).
Kernel Control Path: A set of instructions that the kernel executes in order to
handle a system call. Normally, instructions are executed in order, but some
activities force the CPU to interleave control routes. In user mode, the following
system call is made: The scheduler chooses a new process to run and switches it
on. On behalf of two separate processes, two control pathways are executed.
22