0% found this document useful (0 votes)
29 views51 pages

Operating System - Compressed

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views51 pages

Operating System - Compressed

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Operating System

Unit-1
Services of OS
• User Interface
• Program Execution
• I/O Operation
• File System Manipulation
• Communication(Inter-process Communication)
• Error Detection
• Resource Allocation
• Accounting
• Protection & Security
Goals of OS
• Convenience (User-Friendly)
• Efficiency
• Portability
• Reliability
• Scalability
• Robustness
Components
• A computer system can be divided roughly into four components: the
hardware/ the operating system, the application programs/ and the
users (Figure 1.1).
• The hardware- the central processing unit, the memory, and the
input/output devices-provides the basic computing resources for the
system.
• The application programs- word processors/ spreadsheets/
compilers, and Web browsers-define the ways in which these
resources are used to solve users' computing problems.
• The operating system controls the hardware and coordinates its use
among the various application programs for the various users.
Abstract View of Computer System
•.
Components of Computer System

A computer system can be divided into four components, which are as follows −
• Hardware − The hardware is the physical part which we can touch and feel, the central processing unit
(CPU), the memory, and the input/output (I/O) devices are the basic computing resources of a computer
system.
• Application programs − Application programs are user or programmer created programs like compilers,
database systems, games, and business programs that define the ways in which these resources can be used
to solve the computing problems of the users.
• Users − There are different types of users like people, machines, and even other computers which are trying
to solve different problems.
• Operating system − An operating system is the interface between the user and the machine which controls
and coordinates the use of the hardware among the various application programs for the various users.
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 ).
• Example – The Windows NT operating system uses this layered approach as a part of it.
Design Analysis :
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:
• The outermost layer must be the User Interface layer.
• The innermost layer must be the Hardware layer.
• 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.
Layered OS Design

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.
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 :
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.
Operating System View
• The operating system can be observed from the point of view of the user or the system. This is
known as the user view and the system view respectively.
User -View
The user view depends on the system interface that is used by the users. The different types of user
view experiences can be explained as follows −
• If the user is using a personal computer, the operating system is largely designed to make the interaction
easy. Some attention is also paid to the performance of the system, but there is no need for the operating
system to worry about resource utilization. This is because the personal computer uses all the resources
available and there is no sharing.
• If the user is using a system connected to a mainframe or a minicomputer, the operating system is largely
concerned with resource utilization. This is because there may be multiple terminals connected to the
mainframe and the operating system makes sure that all the resources such as CPU, memory, I/O devices
etc. are divided uniformly between them.
• If the user is sitting on a workstation connected to other workstations through networks, then the operating
system needs to focus on both individual usage of resources and sharing though the network. This happens
because the workstation exclusively uses its own resources but it also needs to share files etc. with other
workstations across the network.
• If the user is using a handheld computer such as a mobile, then the operating system handles the usability
of the device including a few remote operations. The battery level of the device is also taken into account.
System View

• According to the computer system, the operating system is the bridge between
applications and hardware. It is most intimate with the hardware and is used to
control it as required.
• The system views the operating system as a resource allocator. There are many
resources such as CPU time, memory space, file storage space, I/O devices etc.
that are required by processes for execution. It is the duty of the operating
system to allocate these resources judiciously to the processes so that the
computer system can run as smoothly as possible.
• The operating system can also work as a control program. It manages all the
processes and I/O devices so that the computer system works smoothly and
there are no errors. It makes sure that the I/O devices work in a proper manner
without creating problems.
• Operating systems can also be viewed as a way to make using hardware easier.
Classification of Operating system

• Batch OS
• Multi-programming OS
• Multitasking OS/Time sharing OS
• Multiprocessing OS
• Real-Time OS
• Distributed OS
• Embedded OS
• Clustered OS
Batch OS
• In this technique, similar types of jobs were batched together and executed in time. People were
used to having a single computer which was called a mainframe.
• In Batch operating system, access is given to more than one person; they submit their respective
jobs to the computer operator which in turn makes batches of similar jobs for the execution.
• The system put all of the jobs in a queue on the basis of first come first serve and then executes
the jobs one by one. The users collect their respective output when all the jobs get executed.
• The purpose of this operating system was mainly to transfer control from one job to another as
soon as the job was completed.
Advantages of Batch Operating System:

Multiple users can share the batch systems.


The idle time for the batch system is very less.
It is easy to manage large work repeatedly in batch systems.

Disadvantages of Batch Operating System:


Batch systems are hard to debug.
It is sometimes costly.
The other jobs will have to wait for an unknown time if any job fails.

Examples of Batch based Operating System: IBM OS/2


Payroll System, Bank Statements, etc.
Multiprogramming Operating System
• Multiprogramming is an extension to batch processing where the CPU is always kept busy. Each process
needs two types of system time: CPU time and IO time.
• In a multiprogramming environment, when a process does its I/O, The CPU can start the execution of other
processes. Therefore, multiprogramming improves the efficiency of the system.
• Multiprogramming increases CPU utilization by organizing jobs (code and data) so that the CPU always has
one to execute.
• Multiprogrammed systems provide an environment in which the various system resources (for example,
CPU, memory, and peripheral devices) are utilized effectively, but they do not provide for user interaction
with the computer system.
Multiprogramming OS
Advantages of Multiprogramming OS
• Throughout the system, it increased as the CPU always had one program to execute.
• Response time can also be reduced.
Disadvantages of Multiprogramming OS
• Multiprogramming systems provide an environment in which various systems resources are used
efficiently, but they do not provide any user interaction with the computer system.

• Example of Multiprogramming OS: WINDOWS, LINUX etc


Multitasking Systems or Time sharing
• Time sharing (or multitasking) is a logical extension of multiprogramming.
• In time-sharing systems, the CPU executes multiple jobs by switching among them, but the switches occur so
frequently that the users can interact with each program while it is running.
• The task can be from a single user or different users also. The time that each task gets to execute is called
quantum. After this time interval is over OS switches over to the next task.
• A time-sharing operating system allows many users to be served simultaneously, so sophisticated CPU
scheduling schemes and Input/output management are required.
Advantages
CPU idle time can be reduced
• Resource Sharing: Time-sharing systems allow multiple users to share
hardware resources such as the CPU, memory, and peripherals,
reducing the cost of hardware and increasing efficiency.
• Improved Productivity: Time-sharing allows users to work
concurrently, thereby reducing the waiting time for their turn to use
the computer. This increased productivity translates to more work
getting done in less time.
• Improved User Experience: Time-sharing provides an interactive
environment that allows users to communicate with the computer in
real-time, providing a better user experience than batch processing.
Disadvantages
• High Overhead: Time-sharing systems have a higher overhead than
other operating systems due to the need for scheduling, context
switching, and other
• Complexity: Time-sharing systems are complex and require advanced
software to manage multiple users simultaneously. This complexity
increases the chance of bugs and errors.
• Security Risks: With multiple users sharing resources, the risk of
security breaches increases. Time-sharing systems require careful
management of user access, authentication, and authorization to
ensure the security of data and software.
Multiprocessing Operating system

• Multiple CPUs are interconnected so that a job can be divided among them for faster execution. When a job
finishes, results from all CPUs are collected and compiled to give the final output.
• These systems have multiple processors working in parallel that share the computer clock, memory, bus,
peripheral devices etc.
• Multiple CPUs can also be used to run multiple jobs simultaneously.
Advantages of multiprocessing operating system are:
• Increased reliability: Due to the multiprocessing system, processing tasks can be distributed among several
processors. This increases reliability as if one processor fails; the task can be given to another processor for
completion.
• Increased throughout: As several processors increase, more work can be done in less
• The economy of Scale: As multiprocessors systems share peripherals, secondary storage devices, and power
supplies, they are relatively cheaper than single-processor systems.
Disadvantages of Multiprocessing operating
System
• Increased Expense
Even though multiprocessor systems are cheaper in the long run than using multiple computer
systems, still they are quite expensive. It is much cheaper to buy a simple single processor system
than a multiprocessor system.
• Complicated Operating System Required
There are multiple processors in a multiprocessor system that share peripherals, memory etc. So, it
is much more complicated to schedule processes and impart resources to processes than in single
processor systems. Hence, a more complex and complicated operating system is required in
multiprocessor systems.
• Large Main Memory Required
All the processors in the multiprocessor system share the memory. So a much larger pool of
memory is required as compared to single processor systems.
Types of multiprocessing systems

Symmetrical multiprocessing operating system:


• In these types of systems, each processor contains a similar copy of the operating system and
they all communicate with each other.
• All the processors are in a peer to peer relationship i.e. no master - slave relationship exists
between them.
• It also results in a system in which all processors are equally burdened at any time.
• The CPU scheduling policies are very simple. Any new job submitted by a user can be assigned to
any processor that is least burdened. It also results in a system in which all processors are equally
burdened at any time.
Symmetrical multiprocessing operating
system
Characteristics of Symmetrical multiprocessing operating system:
• In this system, any processor can run any job or process.
• In this, any processor initiates an Input and Output operation.
Advantages of Symmetrical multiprocessing operating system:
• These systems are fault-tolerant. Failure of a few processors does not bring
the entire system to a halt.
Disadvantages of Symmetrical multiprocessing operating system:
• It is very difficult to balance the workload among processors rationally.
• Specialized synchronization schemes are necessary for managing multiple
processors.
Asymmetric multiprocessing operating system

• In an asymmetric multiprocessing system, there is a master slave relationship between the processors.
• Further, one processor may act as a master processor or supervisor processor while others are treated as
shown below:

• In asymmetric systems, each processor is given a predefined task.


Asymmetric multiprocessing operating
system
• In the above figure, the asymmetric processing system shows that CPU n1 acts as a supervisor
whose function controls other following processors.
• In this type of system, each processor is assigned a specific task, and there is a designated master
processor that controls the activities of other processors.
Advantages:
• In this type of system execution of Input and Output operation or an application program may be
faster in some situations because many processors may be available for a single job.
Disadvantages:
• In this type of multiprocessing operating system the processors are unequally burdened. One
processor may be having a long job queue, while another one may be sitting idle.
• In this system, if the process handling a specific work fails, the entire system will go down.
Real-time operating system (RTOS)
• Real-time operating system (RTOS) is an operating system intended to serve real time application
that process data as it comes in, mostly without buffer delay.
• It is time-bound system that can be defined as fixed time constraints. In this type of system,
processing must be done inside the specified constraints. Otherwise, the system will fail.
• Whenever an event external to the computer occurs, it is communicated to the computer with
the help of some sensor used to monitor the event. The sensor produces the signal that is
interpreted by the operating system as an interrupt. On receiving an interrupt, the operating
system invokes a specific process or a set of processes to serve the interrupt.
Types of RTOS

Three types of RTOS systems are:


Hard Real Time :
• In Hard RTOS, the deadline is handled very strictly which means that given task must start
executing on specified scheduled time, and must be completed within the assigned time
duration.
• Example: Medical critical care system, Aircraft systems, scientific experiments, medical imaging
systems, industrial control systems, weapon systems, robots, air traffic control systems, etc.
Soft Real time:
In this kind of RTOS, there may be a closing date assigned for a particular job, but a delay for a small
amount of time is acceptable. So, cut off dates are treated softly via means of this kind of RTOS.
Example: Various types of Multimedia applications.
RTOS
• In Firm RTOS additionally want to observe the deadlines. However, lacking a closing date might not have a
massive effect, however may want to purposely undesired effects, like a massive discount within the fine of
a product.
• For Example, this system is used in various forms of Multimedia applications.
The advantages of real-time operating systems

• Maximum consumption –
Maximum utilization of devices and systems. Thus more output from all the resources.
• Task Shifting –
Time assigned for shifting tasks in these systems is very less. For example, in older systems, it takes about 10
microseconds. Shifting one task to another and in the latest systems, it takes 3 microseconds.
• Focus On Application –
Focus on running applications and less importance to applications that are in the queue.
• Real-Time Operating System In Embedded System –
Since the size of programs is small, RTOS can also be embedded systems like in transport and others.
• Error Free –
These types of systems are error-free.
• Memory Allocation –
Memory allocation is best managed in these types of systems.
Disadvantages:
• Limited Tasks –
Very few tasks run simultaneously, and their concentration is very less on few applications to
avoid errors.

• Use Heavy System Resources –


Sometimes the system resources are not so good and they are expensive as well.

• Complex Algorithms –
The algorithms are very complex and difficult for the designer to write on.

• Device Driver And Interrupt signals –


It needs specific device drivers and interrupts signals to respond earliest to interrupts
Modes of operation
User Mode
• When an application like MS word handling a text editor runs on the operating system, the system is in user
mode. The mode bit is 0 in that case. The mode bit will change from 1 to 0 if it switches to kernel mode. The
user mode to kernel mode is switched when there is a need to access any device or any interrupt/system call
occurs.

Kernel-mode
• When the system boots, the system starts with kernel mode. And the applications are executed in user
mode. The switch can happen from user mode to kernel mode when
• Interrupt occurs
• Need to access privileged instruction
• Need to access any device
• The mode bit is changed from 0 to 1 in case of the system switch back to user mode.
Modes of Operation
System Calls
• System calls serve as the interface between an operating system and a process. A system calls in computing
is the programmatic method by which a computer program asks the kernel of the operating system it is
running on for a service.
• User programmers can communicate with the operating system to request its services using the interface
that is created by a system call.
• When a process in user mode needs access to a resource, system calls are typically generated. The resource
is then requested from the kernel via a system call.
How system call works ?
Example of System Calls

• Following are the examples of system calls:


• The most common system calls used on Unix system calls, Unix-like, and other POSIX-compliant
operating systems are open, read, write, close, wait, exec, fork, exit, and kill.
• There are hundreds of systems calls in many contemporary operating systems. For instance, Linux
and OpenBSD each have over 300 different calls, NetBSD and FreeBSD both have over 500, and
Windows has close to 2000 system calls, split between win32k and ntdll.
.
Types of System Calls in OS

There are primarily 5 different types of system calls in the operating system:
1. Process Control: The following services are provided by Process Control System calls that are used to control
a process:
• To forcefully abort the process, simply end it normally.
• Execute a process after loading it into the main memory.
• Terminate the current process before starting a new one.
• Wait for a process to complete running. Wait until a specific event happens, then announce its.
• Allocate memory to a process, then release the memory if the process is terminated.
2. File Management: The following services are provided by system call for file management:
• Making and erasing files ,Open the file, then close it, Write to a specific file, read from a specific file.
• To obtain a file's attribute and to change a file's attribute
Types of System Calls in OS(1)(Categories)
3. Device Management: The following services are offered by a system call that controls I/O devices:
• Devices might be needed while a process is running. such as access to the file system, I/O devices, main
memory, etc.
• As a result, it can ask for a device and then release it once the task is complete.
• when a requested device is granted access by the process. It is capable of reading, writing, and repositioning
operations.
• In order to obtain or modify a specific device's attribute.
• To detach a device from the processor that is currently executing a command, the call can be made.
4. Information Maintenance: The system calls for information maintenance call moves data from the user
program to the operating system. Considering this, the services offered by this type of system call are:
• Obtain the system's time or date. Set the system's time or date.
• Obtain system-related information. Configure the system data.
Types of System Calls in OS(2) (Categories)
• Obtain the characteristics of a specific operating system process. Alternatively, of a specific file on the system
or on any attached devices.
• Set the characteristics of a specific operating system process. Alternatively, of a specific file on the system or
on any attached devices.
5. Communication: Such a system call facilitates the system's network connection. The services that these
system calls offer are:
• Open a fresh connection to send the data. After the transmission is finished, disconnect from the
connection.
• On a particular connection, send a message. Obtain communication from a specific connection.
• Identify and connect a specific remote device to the network. Remove a specific remote computer or device
from the network.
Examples of Types of System Calls
Important System Calls Used in OS
1. wait()
• In certain systems, a process must wait for another process to finish running before continuing. When a parent process
creates a child process, the parent process's execution is suspended until the child process has finished running.
• With a wait() system call, the parent process is automatically suspended. Control returns to the parent process once the
child process has completed its execution.
2. fork()
• The fork system call in OS is used by processes to make copies of themselves. By using this system, the Call parent process
can create a child process, and the parent process's execution will be halted while the child process runs.
3. exec()
• When an executable file replaces an earlier executable file within the context of an active process, this system call is
executed. The original process identifier is still present even though a new process is not created; instead, the new
process replaces the old one's stack, data, head, data, etc.
4. kill()
• The OS uses the kill() system call to urge processes to terminate by sending them a signal. A kill system call can have
different meanings and is not always used to end a process.
5. exit()
• An exit system call is used when the programme must be stopped. When the exit system call is used, the resources that
the process was using were released.
Fork() system call
• The fork() System Call is used to create processes. It does not take any arguments and returns a process ID
(mostly an integer value).
• Fork system call creates a new process (called child process) that runs concurrently with the parent process
(the process that makes the fork() call).
Fork() return the following values:
• Negative value - it represents the creation of the child process was unsuccessful.
• Zero - it represents a new child process is created.
• Positive value - The process ID of the child process to the parent. The returned process ID is type pid_t defined in
sys/types.h. Usually, the process ID is an integer.
• Since the child and parent processes run concurrently, these processes reside in different memory spaces.
Code (Do refer class examples too)
Example1:
Code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
//main function begins
int main()
{ fork();
fork();
fork();
printf("this process is created by fork() system call\n");
return 0; }
Output:
this process is created by fork() system call
this process is created by fork() system call
this process is created by fork() system call
this process is created by fork() system call
this process is created by fork() system call
this process is created by fork() system call
this process is created by fork() system call
this process is created by fork() system call
Here, the total number of processes created is 2^3 = 8, and the print statement is executed eight times.
Kernel(The Kernel is the heart of your operating system. Kernel handles all operations on
behalf of operating system.)

• A Kernel is a computer program at the core of a computer's operating system. It generally has complete
control over everything.
• It is one of the first programs to be loaded up on the memory before the boot loader. It manages the
memory as well as peripherals such as keyboards and monitors.
• It acts as a primary interface between the hardware and the processes of a computer. The Kernel connects
these two to adjust resources as effectively as possible.
Functions of a Kernel
• Device Management: Processes require various peripheral devices such as a mouse and keyboard connected
to the computer to perform various tasks. The Kernel manages the allocation of the peripheral devices.
• Resource Management: Kernel shares the resources between different processes while ensuring that every
process has unfirm access to the resources.
• Memory management: Every process requires some memory to execute. The Kernel allows the processes to
access the memory safely. It is responsible for allocating and deallocating memory to processes for their
execution.
• Access Computer Resource: A kernel can access different computer resources such as RAM, CPU, I/O
devices, and other resources. Every program needs to access the memory to execute. The Kernel decides
which memory each process will use, and the action is taken if memory is unavailable.
Types of Kernels
Monolithic Kernels (All the services run in kernel space.)
• The Kernel and user-space use the same memory space in a monolithic kernel. This means that no different
memory space is used for user services and kernel services.
• All the services are in kernel mode, and the entire kernel functionality is organized into a single block that is
difficult to debug and maintain.
• A monolithic kernel is an operating system architecture where the entire operating system is working in
kernel space.
• Example: Unix, Linux, XTS-400, etc.
Following are the primary functions of a monolithic kernel:
• This kernel provides file management, CPU scheduling, memory management, and other operating system
functions through system calls.
• It also provides complete control over components like Interprocess communication(IPC), I/O and device
management, fundamental process management, and hardware.
Monolithic Kernel
Advantages/Disadvantages

Advantages
• It gives better performance than the microkernel.
• There's no additional communication overhead, unlike microkernel.
• It provides effective services like IPC through system calls.
• A single extensive process can run entirely in a single address space which enhances the security of the
process as well from interference.
Disadvantages
• One of the major disadvantages of a monolithic kernel is that if anyone service fails it leads to an entire
system failure.
• If the user has to add any new service. The user needs to modify the entire operating system.
Microkernel

• In this type of Kernel, the user and Kernel services are implemented into two different address
spaces, i.e., user and kernel spaces.
• Only the most important services are inside the kernel and the rest of the OS services are present
inside the system application program. Thus users are able to interact with those not-so-
important services within the system application.
• the microkernel is solely responsible for the most important services of the operating system they
are named as follows: Inter process-Communication, Memory Management, CPU-Scheduling.
• 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.
• In microkernels, there will be no system crash when a process crashes, and it can be resolved by
just restarting the error-caused services.
Micro-Kernal
Monolithic VS Microkernel
S. No. Parameters Microkernel Monolithic kernel

In microkernel, user services and kernel services are kept in In monolithic kernel, both user services and kernel services are kept in
1. Address Space
separate address space. the same address space.

2. Design and Implementation OS is complex to design. OS is easy to design and implement.

3. Size Microkernel are smaller in size. Monolithic kernel is larger than microkernel.

4. Functionality Easier to add new functionalities. Difficult to add new functionalities.

5. Coding To design a microkernel, more code is required. Less code when compared to microkernel

Failure of one component does not effect the working of micro Failure of one component in a monolithic kernel leads to the failure of
6. Failure
kernel. the entire system.

7. Processing Speed Execution speed is low. Execution speed is high.

8. Extend It is easy to extend Microkernel. It is not easy to extend monolithic kernel.

To implement IPC messaging queues are used by the Signals and Sockets are utilized to implement IPC in monolithic
9. Communication
communication microkernels. kernels.

10. Debugging Debugging is simple. Debugging is difficult.

The kernel only offers IPC and low-level device management


13. Services The Kernel contains all of the operating system’s services.
services.

14. Example Example : Mac OS X. Example : Microsoft Windows 95.

You might also like