Chapter-2 Operating System Structure Er. Dependra Ramtel

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

Chapter-2

Operating System Structure

Er. Dependra Ramtel

Content
 Introduction,
 Layered System,
 Kernel, Types of Kernel (Monolithic/Macro Kernel and Micro / Exo-
Kernel),
 Client-Server Model,
 Virtual Machines, Shell.
Kernel:
 The kernel is a computer program at the core of a computer’s operating
system and has complete control over everything in the system.it is the
portion of the operating system code that is always resident in memory
and facilites interactions between software and hardware components.
 It is the essential part of an operating system which is lodaded firstly at
the time of booting and remains in the memory until the computer
system is switched off.
 Because it stays in memory, it is important for the kernel to be as small
as possible while still providing all the essential services required by
other parts of the OS and applications.
 The kernel code is usually loaded into a protected area of memory to
prevent it from being overwritten by programs or other part of OS.
 When running in kernel mode, the CPU can execute every instruction in
its instruction set and use every feature of hardware.
 In contrast, user mode permits only a subset of the instruction and
features to be accessed. Generally, all instructions involving I/O and
memory protection are disallowed in user mode.
 Typically, the kernel is responsible for:
o Memory management
o Process and task management and
o Disk management
o Interrupt Handling
o I/O Communication
 It connects the system hardware to the application software.
 Instead of large kernel , most of the operating system being build now
uses micro-kernel, which minimizes the sizes of the kernel and results
that many traditional services are made into user level services.
SYSTEM CALLS
 A system call is a mechanism used by an application for requesting a
service from the operating system, i.e., it is the interface between the
operating system and the user program.
 If a process is running a user program in user mode and needs a system
service (for example, reading data from a file), it has to execute a trap or
system call instruction to transfer control to the operating system. The
operating system then figures out what the calling process wants. Then
it carries out the system call and returns control to the instruction
following the system call.
 The interface between the operating system and the user
programs(processes) is defined by the set of system calls that the
operating system provides.
 System calls are usually made when a process in user mode requires
access to the resources.
 Then it requests the kernel to provide the resource via a system call.
 The main propose of system calls is to send request from the user-level
processes to the OS.

 As we see from the diagram , the process execute normally in user mode
until a system call interrupts this.
 Then the system call is executed on the priority basis in kernel mode
 After the execution of system call, the control return to user mode &
execution of user processes can be resumed.
In general system calls are required in the following situation:
 Creation and management of new processes.
 If file system requires the creation & deletion of files. Reading & writing
from files also requires a system call.
 Network connection also requires system calls. This includes sending &
receiving packets.
 Access to hardware device such as printer , hard disks ,scanner etc.
requires a system calls.

TYPES OF SYSTEM CALLS


Mainly 5 types of system calls
A. Process control : These system call deals with processes such as process
creation , process termination etc.[CreatProcess() ,ExitProcess() etc.]
B. File Management: These system calls are responsible for file manipulation
such as creating a file , reading a file , writing into a file,delete file.
etc.[CreateFile(),ReadFile,WriteFile()]
C. Device management: These system calls are responsible for device
manipulation such as reading from a device buffers, writing into device buffers
etc.[SetConsole Mode()ReadConsole() WriteConsole()]
D. Information Management : These system calls handles information & its
transfer between the operating system & the user
program[GetCurrentProcessID(),SetTimer() Sleep()]
E. Communication : These system calls are useful for inter process
communication(IPC) . They also deals with creating & deleting a
communication connection[SetFileSecurity(),InitilizeSecurityDescriptor()]

Two modes of operation in the operating system


User Mode
The system is in user mode when the operating system is running a user
application such as handling a text editor. The transition from user mode to
kernel mode occurs when the application requests the help of operating system
or an interrupt or a system call occurs.
The mode bit is set to 1 in the user mode. It is changed from 1 to 0 when
switching from user mode to kernel mode.
Kernel Mode
The system starts in kernel mode when it boots and after the operating system
is loaded, it executes applications in user mode. There are some privileged
instructions that can only be executed in kernel mode.
These are interrupt instructions, input output management etc. If the privileged
instructions are executed in user mode, it is illegal and a trap is generated.
The mode bit is set to 0 in the kernel mode. It is changed from 0 to 1 when
switching from kernel mode to user mode.
An image that illustrates the transition from user mode to kernel mode and back
again is

In the above image, the user process executes in the user mode until it gets a
system call. Then a system trap is generated and the mode bit is set to zero. The
system call gets executed in kernel mode. After the execution is completed,
again a system trap is generated and the mode bit is set to 1. The system control
returns to kernel mode and the process execution continues.
Trap : A trap is a software generated interrupt caused by either by error or by
specific request from a user that an operating system service be provided.
Structures of Operating Systems
Operating system can be implemented with the help of various structures. The
structure of the OS depends mainly on how the various common components of
the operating system are interconnected and melded into the kernel.
Depending on this we have following structures of the operating system:
Simple Structure
 Simple Structure operating systems do not have well defined structure
and are small, simple and limited systems.
 The interfaces and levels of functionality are not well separated. MS-
DOS is an example of such operating system.
 In MS-DOS application programs are able to access the basic I/O
routines.
 These types of operating system cause the entire system to crash if one
of the user programs fails.
 The given figure illustrate the structure of MS-DOS.

Advantages of Simple structure:


 It delivers better application performance because of the few interfaces
between the application program and the hardware.
 Easy for kernel developers to develop such an operating system.
Disadvantages of Simple structure:
 The structure is very complicated as no clear boundaries exists between
modules.
 It does not enforce data hiding in the operating system.

Monolithic Structure
 The monolithic operating system is a very basic operating system in
which file management, memory management, device management,
and process management are directly controlled within the kernel.
 The kernel can access all the resources present in the system.
 In monolithic systems, each component of the operating system is
contained within the kernel.
 The monolithic operating system is also known as the monolithic kernel.
 This is an old operating system used to perform small tasks like batch
processing and time-sharing tasks in banks.
 The monolithic kernel acts as a virtual machine that controls all
hardware parts.

Advantages of Monolithic Kernel

Here are the following advantages of a monolithic kernel, such as:

o The execution of the monolithic kernel is quite fast as the services such as
memory management, file management, process scheduling, etc., are
implemented under the same address space.
o A process runs completely in single address space in the monolithic
kernel.

Disadvantages of Monolithic Kernel

Here are some disadvantages of the monolithic kernel, such as:


o If any service fails in the monolithic kernel, it leads to the failure of the
entire system.
o The entire operating system needs to be modified by the user to add any
new service.

Layered Structure
 Layered Structure is a type of system structure in which the different
services of the operating system are split into various layers, where
each layer has a specific well-defined task to perform.
 It was created to improve the pre-existing structures like the
Monolithic structure ( UNIX ) and the Simple structure ( MS-DOS ).
 Os/2 operating system is example of layered architecture of operating
system another example is earlier version of Windows NT.
 The whole Operating System is separated into several layers ( from 0 to
n ) as the diagram shows. Each of the layers must have its own specific
function to perform.
There are some rules in the implementation of the layers as follows.
1. The outermost layer must be the User Interface layer.
2. The innermost layer must be the Hardware layer.
3. A particular layer can access all the layers present below it but it cannot
access the layers present above it. That is layer n-1 can access all the
layers from n-2 to 0 but it cannot access the nth layer.

 Thus if the user layer wants to interact with the hardware layer, the
response will be traveled through all the layers from n-1 to 1. Each
layer must be designed and implemented such that it will need only the
services provided by the layers below it.
Fig. of Layer Structure

Advantages :
There are several advantages to this design :
1. Modularity :
This design promotes modularity as each layer performs only the tasks it is
scheduled to perform.
2. Easy debugging :
As the layers are discrete so it is very easy to debug. Suppose an error
occurs in the CPU scheduling layer, so the developer can only search that
particular layer to debug, unlike the Monolithic system in which all the
services are present together.
3. Easy update :
A modification made in a particular layer will not affect the other layers.
4. No direct access to hardware :
The hardware layer is the innermost layer present in the design. So a user
can use the services of hardware but cannot directly modify or access it,
unlike the Simple system in which the user had direct access to the
hardware.
5. Abstraction :
Every layer is concerned with its own functions. So the functions and
implementations of the other layers are abstract to it.

Disadvantages :
Though this system has several advantages over the Monolithic and Simple
design, there are also some disadvantages as follows.
1. Complex and careful implementation :
As a layer can access the services of the layers below it, so the
arrangement of the layers must be done carefully. For example, the
backing storage layer uses the services of the memory management layer.
So it must be kept below the memory management layer. Thus with great
modularity comes complex implementation.
2. Slower in execution :
If a layer wants to interact with another layer, it sends a request that has
to travel through all the layers present in between the two interacting
layers. Thus it increases response time, unlike the Monolithic system
which is faster than this. Thus an increase in the number of layers may
lead to a very inefficient design.

Microkernel Structure
 A microkernel is one of the classifications of the kernel. Being a kernel
it manages all system resources.
 But in a microkernel, the user services and kernel services are
implemented in different address spaces. The user services are kept
in user address space, and kernel services are kept under kernel
address space, thus also reduces the size of kernel and size of an
operating system as well.
 It provides a minimal amount of process and memory management
services.
 The interaction between the client application and services running in
user address space is established via message passing that helps to
reduce the speed of microkernel execution.
 The OS is unaffected because kernel and user services are isolated, so if
any of the user services fails, the kernel service is unaffected.
 It is extendable because new services are added to the user address
space, hence requiring no changes in kernel space.
 It's also lightweight, secure, and reliable.
 In the above figure, the microkernel includes basic needs like process
scheduling mechanisms, memory, and interprocess communication. It is
the only program that executes at the privileged level, i.e., kernel mode.
The OS's other functions are moved from the kernel-mode and execute
in the user mode.
 Since the kernel is the most crucial OS component, it is responsible for the
essential services. As a result, under this design, only the most significant
services are present inside the kernel in this architecture. In contrast, the
rest operating system services are available inside the system application
software. As a result, users can interact with such unnecessary services
within the system application. The microkernel is entirely responsible for
the operating system's most significant services, which are as follows:

1. Inter-Process Communication
2. Memory Management
3. CPU Scheduling

Advantages
1. Microkernels are secure since only those parts are added, which might
disturb the system's functionality.
2. Microkernels are modular, and the various modules may be swapped,
reloaded, and modified without affecting the kernel.
3. Microkernel architecture is compact and isolated, so it may perform
better.
4. The system expansion is more accessible, so it may be introduced to the
system application without disrupting the kernel.
5. When compared to monolithic systems, microkernels have fewer system
crashes. Furthermore, due to the modular structure of microkernels, any
crashes that do occur are simply handled.
6. The microkernel interface helps in enforcing a more modular system
structure.
7. Server failure is treated the same as any other user program failure.
8. It adds new features without recompiling.

Disadvantages
1. When the drivers are implemented as procedures, a context switch or a
function call is needed.
2. In a microkernel system, providing services are more costly than in a
traditional monolithic system.
3. The performance of a microkernel system might be indifferent and cause
issues.

Client Server Structure


 Two classes of processes - Server and Clients
 Communication between client and server is via message passing
 Client and server can run on different computers connected by
LAN/WAN
 Servers run as user mode. Hence, no system down even if the server
crashed
 Well adopted in distributed system
 E.g. Windows NT

Fig. Client-Server model over a network


Virtual Machines:
 Virtual machine is an illusion of a real machine.
 It is created by a real machine operating system, which make a single
real machine appears to be several real machine.
 The architecture of virtual machine is shown below.
 The best example of virtual machine architecture is IBM 370 computer.
 In this system each user can choose a different operating system.
 Actually, virtual machine can run several operating systems at once,
each of them on its virtual machine.
 Its multiprogramming shares the resource of a single machine in
different manner.
Fig. Vmware Architecture

Advantages of virtual machine :


 The virtual-machine concept provides complete protection of system
resources since each virtual machine is isolated from all other virtual
machines. This isolation, however, permits no direct sharing of
resources.
 A virtual-machine system is a perfect vehicle for operating systems
research and development. System development is done on the virtual
machine, instead of on a physical machine and so does not disrupt
normal system operation.
Disadvantage of virtual machine :
 The virtual machine concept is difficult to implement due to the effort
required to provide an exact duplicate to the underlying machine

ExoKernel Structure
 Exokernel is an operating system developed at the MIT that provides
application-level management of hardware resources.
 This architecture is designed to separate resource protection from
management to facilitate application-specific customization.

 The exokernel architecture is built such that a small kernel moves all
hardware abstractions into untrusted libraries known as library
operating systems.
 The main goal of an exokernel is to ensure that there is no forced
abstraction, which is what makes an exokernel different from micro- and
monolithic kernels.
 Some of the features of exokernel operating systems include:

 Better support for application control


 Separates security from management
 Abstractions are moved securely to an untrusted library operating
system
 Provides a low-level interface
 Library operating systems offer portability and compatibility

The benefits of the exokernel operating system include:

 Improved performance of applications


 More efficient use of hardware resources through precise resource
allocation and revocation
 Easier development and testing of new operating systems
 Each user-space application is allowed to apply its own optimized
memory management
Some of the drawbacks of the exokernel operating system include:

 Reduced consistency
 Complex design of exokernel interfaces

Shell
 A shell is an environment or a special user program which provide an
interface to user to use operating system services.
 It executes programs based on the input provided by the user.
 The term shell derives its name form the fact that it is an outer layer of
the OS.
 A shell is a program that provides the traditional text only user interface
for Linux and other Unix operating system.
 In computing, a shell is a piece of software that provides an interface for
users and provides access to the services of a kernel.
 Its primary function is to read commands typed into a console or
terminal window and then execute it.
 Shell is also called the Command Line Interpreter (CLI) or the “C”
prompt.
 A shell is an interface between the user and the internal part of the
operating system.
 A user is in shell(i.e interacting with the shell) as soon as the user has
logged into the system.
 A shell is the most fundamental way that user can interact with the
system and the shell hides the detail of the underlying system from the
user.
 Example: Bourne Shell, Bash shell, Korn Shell, C shell
OPEN SOURCE OPERATING SYSTEM
 Open source refers to any program whose source code is made available
for use or modification as users or other developers see it.
 It is usually developed as a public collaboration & made freely available.
 These are released under license where the copyright holder allows to
study, change as well as distribute the software to other people.
 The different source operating system available in market are:
Cosmos
FreeDos
Genode
Ghost OS
ITS Osv
Phantom OS

Difference between Shell and Kernel :


S.No.Shell Kernel
Shell allows the users to Kernel controls all the tasks of
1. communicate with the kernel. the system.

It is the interface between It is the core of the operating


2. kernel and user. system.

Its a low level program


interfacing with the hardware
It is a command line interpreter (CPU, RAM, disks) on top of
3. (CLI). which applications are running.

Its types are – Monolithic


Its types are – Bourne Shell, C Kernel, Micro kernel, Hybrid
4. shell, Korn Shell, etc. kernel, etc.

It carries out commands on a


group of files by specifying a It performs memory
5. pattern to match management.

Shell commands like ls, mkdir It performs process


6. and many more can be used to management.
request to complete the specific
operation to the OS.

7. It is the outer layer of OS. It is the inner layer of OS.

Kernel directly interacts with


It interacts with user and the hardware by accepting
interprets to machine machine understandable
8. understandable language. language from the shell.

You might also like