Operating Systems

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 26

Operating Systems

Unit 1 :
Introduction
An Operating System (OS) is an interface between a computer user and
computer hardware. An operating system is a software which performs all the
basic tasks like file management, memory management, process
management, handling input and output, and controlling peripheral devices
such as disk drives and printers.
Some popular Operating Systems include Linux Operating System, Windows
Operating System, VMS, OS/400, AIX, z/OS, etc.

Definition
An operating system is a program that acts as an interface between the user
and the computer hardware and controls the execution of all kinds of
programs.

Functions of Operating Systems :

Functions of Operating system – Operating system performs three functions:


1. Convenience: An OS makes a computer more convenient to use.
2. Efficiency: An OS allows the computer system resources to be used in an
efficient manner.
3. Ability to Evolve: An OS should be constructed in such a way as to
permit the effective development, testing and introduction of new system
functions at the same time without interfering with service.

Following are some of important functions of an operating System.

 Memory Management
 Processor Management
 Device Management
 File Management
 Security
 Control over system performance
 Job accounting
 Error detecting aids
 Coordination between other software and users

Memory Management
Memory management refers to management of Primary Memory or Main
Memory. Main memory is a large array of words or bytes where each word or
byte has its own address.
Main memory provides a fast storage that can be accessed directly by the
CPU. For a program to be executed, it must in the main memory. An
Operating System does the following activities for memory management −
 Keeps tracks of primary memory, i.e., what part of it are in use by
whom, what part are not in use.
 In multiprogramming, the OS decides which process will get memory
when and how much.
 Allocates the memory when a process requests it to do so.
 De-allocates the memory when a process no longer needs it or has been
terminated.
Processor Management
In multiprogramming environment, the OS decides which process gets the
processor when and for how much time. This function is called process
scheduling. An Operating System does the following activities for processor
management −
 Keeps tracks of processor and status of process. The program
responsible for this task is known as traffic controller.
 Allocates the processor (CPU) to a process.
 De-allocates processor when a process is no longer required.

Device Management
An Operating System manages device communication via their respective
drivers. It does the following activities for device management −
 Keeps tracks of all devices. Program responsible for this task is known as
the I/O controller.
 Decides which process gets the device when and for how much time.
 Allocates the device in the efficient way.
 De-allocates devices.

File Management
A file system is normally organized into directories for easy navigation and
usage. These directories may contain files and other directions.
An Operating System does the following activities for file management −
 Keeps track of information, location, uses, status etc. The collective
facilities are often known as file system.
 Decides who gets the resources.
 Allocates the resources.
 De-allocates the resources.

Other Important Activities


Following are some of the important activities that an Operating System
performs −
 Security − By means of password and similar other techniques, it
prevents unauthorized access to programs and data.
 Control over system performance − Recording delays between request
for a service and response from the system.
 Job accounting − Keeping track of time and resources used by various
jobs and users.
 Error detecting aids − Production of dumps, traces, error messages, and
other debugging and error detecting aids.
 Coordination between other softwares and users − Coordination and
assignment of compilers, interpreters, assemblers and other software
to the various users of the computer systems.

Characteristics of Operating Systems :

Batch processing :
Batch processing is a technique in which an Operating System collects the
programs and data together in a batch before processing starts. An operating
system does the following activities related to batch processing −
 The OS defines a job which has predefined sequence of commands,
programs and data as a single unit.
 The OS keeps a number a jobs in memory and executes them without
any manual information.
 Jobs are processed in the order of submission, i.e., first come first
served fashion.
 When a job completes its execution, its memory is released and the
output for the job gets copied into an output spool for later printing or
processing.
Advantages
 Batch processing takes much of the work of the operator to the
computer.
 Increased performance as a new job get started as soon as the previous
job is finished, without any manual intervention.

Disadvantages

 Difficult to debug program.


 A job could enter an infinite loop.
 Due to lack of protection scheme, one batch job can affect pending jobs.

Multitasking
Multitasking is when multiple jobs are executed by the CPU simultaneously by
switching between them. Switches occur so frequently that the users may
interact with each program while it is running. An OS does the following
activities related to multitasking −
 The user gives instructions to the operating system or to a program
directly, and receives an immediate response.
 The OS handles multitasking in the way that it can handle multiple
operations/executes multiple programs at a time.
 Multitasking Operating Systems are also known as Time-sharing
systems.
 These Operating Systems were developed to provide interactive use of a
computer system at a reasonable cost.
 A time-shared operating system uses the concept of CPU scheduling and
multiprogramming to provide each user with a small portion of a time-
shared CPU.
 Each user has at least one separate program in memory.

 A program that is loaded into memory and is executing is commonly


referred to as a process.
 When a process executes, it typically executes for only a very short time
before it either finishes or needs to perform I/O.
 Since interactive I/O typically runs at slower speeds, it may take a long
time to complete. During this time, a CPU can be utilized by another
process.
 The operating system allows the users to share the computer
simultaneously. Since each action or command in a time-shared system
tends to be short, only a little CPU time is needed for each user.
 As the system switches CPU rapidly from one user/program to the next,
each user is given the impression that he/she has his/her own CPU,
whereas actually one CPU is being shared among many users.

Multiprogramming
Sharing the processor, when two or more programs reside in memory at the
same time, is referred as multiprogramming. Multiprogramming assumes a
single shared processor. Multiprogramming increases CPU utilization by
organizing jobs so that the CPU always has one to execute.
The following figure shows the memory layout for a multiprogramming
system.

An OS does the following activities related to multiprogramming.


 The operating system keeps several jobs in memory at a time.
 This set of jobs is a subset of the jobs kept in the job pool.
 The operating system picks and begins to execute one of the jobs in the
memory.
 Multiprogramming operating systems monitor the state of all active
programs and system resources using memory management programs
to ensures that the CPU is never idle, unless there are no jobs to
process.

Advantages

 High and efficient CPU utilization.


 User feels that many programs are allotted CPU almost simultaneously.
Disadvantages

 CPU scheduling is required.


 To accommodate many jobs in memory, memory management is
required.

Interactivity
Interactivity refers to the ability of users to interact with a computer system.
An Operating system does the following activities related to interactivity −

 Provides the user an interface to interact with the system.


 Manages input devices to take inputs from the user. For example,
keyboard.
 Manages output devices to show outputs to the user. For example,
Monitor.
The response time of the OS needs to be short, since the user submits and
waits for the result.

Real Time System


Real-time systems are usually dedicated, embedded systems. An operating
system does the following activities related to real-time system activity.

 In such systems, Operating Systems typically read from and react to


sensor data.
 The Operating system must guarantee response to events within fixed
periods of time to ensure correct performance.

Distributed Environment
A distributed environment refers to multiple independent CPUs or processors
in a computer system. An operating system does the following activities
related to distributed environment −
 The OS distributes computation logics among several physical
processors.
 The processors do not share memory or a clock. Instead, each processor
has its own local memory.
 The OS manages the communications between the processors. They
communicate with each other through various communication lines.

Spooling
Spooling is an acronym for simultaneous peripheral operations on line.
Spooling refers to putting data of various I/O jobs in a buffer. This buffer is a
special area in memory or hard disk which is accessible to I/O devices.
An operating system does the following activities related to distributed
environment −
 Handles I/O device data spooling as devices have different data access
rates.
 Maintains the spooling buffer which provides a waiting station where
data can rest while the slower device catches up.
 Maintains parallel computation because of spooling process as a
computer can perform I/O in parallel fashion. It becomes possible to
have the computer read data from a tape, write data to disk and to
write out to a tape printer while it is doing its computing task.

Advantages

 The spooling operation uses a disk as a very large buffer.


 Spooling is capable of overlapping I/O operation for one job with
processor operations for another job.
Services of Operating System :
An Operating System provides services to both the users and to the programs.

 It provides programs an environment to execute.


 It provides users the services to execute the programs in a convenient
manner.
Following are a few common services provided by an operating system −

 Program execution
 I/O operations
 File System manipulation
 Communication
 Error Detection
 Resource Allocation
 Protection

Program execution
Operating systems handle many kinds of activities from user programs to
system programs like printer spooler, name servers, file server, etc. Each of
these activities is encapsulated as a process.
A process includes the complete execution context (code to execute, data to
manipulate, registers, OS resources in use). Following are the major activities
of an operating system with respect to program management −

 Loads a program into memory.


 Executes the program.
 Handles program's execution.
 Provides a mechanism for process synchronization.
 Provides a mechanism for process communication.
 Provides a mechanism for deadlock handling.

I/O Operation
An I/O subsystem comprises of I/O devices and their corresponding driver
software. Drivers hide the peculiarities of specific hardware devices from the
users.
An Operating System manages the communication between user and device
drivers.

 I/O operation means read or write operation with any file or any specific
I/O device.
 Operating system provides the access to the required I/O device when
required.

File system manipulation


A file represents a collection of related information. Computers can store files
on the disk (secondary storage), for long-term storage purpose. Examples of
storage media include magnetic tape, magnetic disk and optical disk drives
like CD, DVD. Each of these media has its own properties like speed, capacity,
data transfer rate and data access methods.
A file system is normally organized into directories for easy navigation and
usage. These directories may contain files and other directions. Following are
the major activities of an operating system with respect to file management −

 Program needs to read a file or write a file.


 The operating system gives the permission to the program for operation
on file.
 Permission varies from read-only, read-write, denied and so on.
 Operating System provides an interface to the user to create/delete
files.
 Operating System provides an interface to the user to create/delete
directories.
 Operating System provides an interface to create the backup of file
system.

Communication
In case of distributed systems which are a collection of processors that do not
share memory, peripheral devices, or a clock, the operating system manages
communications between all the processes. Multiple processes communicate
with one another through communication lines in the network.
The OS handles routing and connection strategies, and the problems of
contention and security. Following are the major activities of an operating
system with respect to communication −
 Two processes often require data to be transferred between them
 Both the processes can be on one computer or on different computers,
but are connected through a computer network.
 Communication may be implemented by two methods, either by Shared
Memory or by Message Passing.

Error handling
Errors can occur anytime and anywhere. An error may occur in CPU, in I/O
devices or in the memory hardware. Following are the major activities of an
operating system with respect to error handling −

 The OS constantly checks for possible errors.


 The OS takes an appropriate action to ensure correct and consistent
computing.

Resource Management
In case of multi-user or multi-tasking environment, resources such as main
memory, CPU cycles and files storage are to be allocated to each user or job.
Following are the major activities of an operating system with respect to
resource management −

 The OS manages all kinds of resources using schedulers.


 CPU scheduling algorithms are used for better utilization of CPU.

Protection
Considering a computer system having multiple users and concurrent
execution of multiple processes, the various processes must be protected
from each other's activities.
Protection refers to a mechanism or a way to control the access of programs,
processes, or users to the resources defined by a computer system. Following
are the major activities of an operating system with respect to protection −

 The OS ensures that all access to system resources is controlled.


 The OS ensures that external I/O devices are protected from invalid
access attempts.
 The OS provides authentication features for each user by means of
passwords.
System Calls :
Introduction of System Call

In computing, a system call is the programmatic way in which a computer


program requests a service from the kernel of the operating system it is
executed on. A system call is a way for programs to interact with the operating
system. A computer program makes a system call when it makes a request to
the operating system’s kernel. System call provides the services of the
operating system to the user programs via Application Program Interface(API).
It provides an interface between a process and operating system to allow user-
level processes to request services of the operating system. System calls are
the only entry points into the kernel system. All programs needing resources
must use system calls.
Services Provided by System Calls :
1. Process creation and management
2. Main memory management
3. File Access, Directory and File system management
4. Device handling(I/O)
5. Protection
6. Networking, etc.

Types of System Calls : There are 5 different categories of system calls –


1. Process control: end, abort, create, terminate, allocate and free
memory.
2. File management: create, open, close, delete, read file etc.
3. Device management
4. Information maintenance
5. Communication

Types of System Calls


There are mainly five types of system calls. These are explained in detail as
follows:

Process Control
These system calls deal with processes such as process creation, process
termination etc.
File Management
These system calls are responsible for file manipulation such as creating a file,
reading a file, writing into a file etc.

Device Management
These system calls are responsible for device manipulation such as reading
from device buffers, writing into device buffers etc.

Information Maintenance
These system calls handle information and its transfer between the operating
system and the user program.

Communication
These system calls are useful for interprocess communication. They also deal
with creating and deleting a communication connection.
Some of the examples of all the above types of system calls in Windows and
Unix are given as follows:
Types of System Calls Windows Linux

CreateProcess() fork()
Process Control ExitProcess() exit()
WaitForSingleObject() wait()

CreateFile() open()
ReadFile() read()
File Management
WriteFile() write()
CloseHandle() close()

SetConsoleMode() ioctl()
Device Management ReadConsole() read()
WriteConsole() write()
Information Maintenance GetCurrentProcessID() getpid()
SetTimer() alarm()
Sleep() sleep()

CreatePipe() pipe()
Communicationa CreateFileMapping() shmget()
MapViewOfFile() mmap()

There are many different system calls as shown above. Details of some of
those system calls are as follows:

open()
The open() system call is used to provide access to a file in a file system. This
system call allocates resources to the file and provides a handle that the
process uses to refer to the file. A file can be opened by multiple processes at
the same time or be restricted to one process. It all depends on the file
organisation and file system.

read()
The read() system call is used to access data from a file that is stored in the
file system. The file to read can be identified by its file descriptor and it should
be opened using open() before it can be read. In general, the read() system
calls takes three arguments i.e. the file descriptor, buffer which stores read
data and number of bytes to be read from the file.

write()
The write() system calls writes the data from a user buffer into a device such
as a file. This system call is one of the ways to output data from a program. In
general, the write system calls takes three arguments i.e. file descriptor,
pointer to the buffer where data is stored and number of bytes to write from
the buffer.

close()
The close() system call is used to terminate access to a file system. Using this
system call means that the file is no longer required by the program and so
the buffers are flushed, the file metadata is updated and the file resources are
de-allocated.
System Programs
There are mainly two categories of programs i.e. application programs and
system programs. A diagram that demonstrates their place in the logical
computer hierarchy is as follows:

Application Programs
These programs perform a particular function directly for the users. Some of
the common application programs include Email, web browsers, gaming
software, word processors, graphics software, media player etc.
All of these programs provide an application to the end users, so they are
known as application programs. For example: a web browser is used to find
information while a gaming software is used to play games.
The requests for service and application communication systems used in an
application by a programmer is known as an application program interface
(API).

System Programs
The system programs are used to program the operating system software.
While application programs provide software that is used directly by the user,
system programs provide software that are used by other systems such as SaaS
applications, computational science applications etc.
The attributes of system programming are:

 Using system programming, a programmer can make assumptions about


the hardware of the system that the program runs on.
 A low level programming language is used in system programming
normally. This is so that the programs can operate in low resource
environments easily.
 Most system programs are created to have a low runtime overhead.
These programs may have small runtime library.
 Some parts of the system programs may be directly written in assembly
language by the programmers.
 A debugger cannot be used on system programs mostly. This problem
can be solved by running the programs in a simulated environment.

Some examples of system programs are operating system, networking system,


web site server, data backup server etc.

Operating System 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.
An image to illustrate the structure of MS-DOS is as follows:

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.
An image demonstrating the layered approach is as follows:
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.
Operating System Generations
Operating Systems have evolved over the years. So, their evolution through
the years can be mapped using generations of operating systems. There are
four generations of operating systems. These can be described as follows:

The First Generation ( 1945 - 1955 ): Vacuum Tubes and Plugboards


Digital computers were not constructed until the second world war. Calculating
engines with mechanical relays were built at that time. However, the
mechanical relays were very slow and were later replaced with vacuum tubes.
These machines were enormous but were still very slow.
These early computers were designed, built and maintained by a single group
of people. Programming languages were unknown and there were no
operating systems so all the programming was done in machine language. All
the problems were simple numerical calculations.
By the 1950’s punch cards were introduced and this improved the computer
system. Instead of using plugboards, programs were written on cards and read
into the system.

The Second Generation ( 1955 - 1965 ): Transistors and Batch Systems


Transistors led to the development of the computer systems that could be
manufactured and sold to paying customers. These machines were known as
mainframes and were locked in air-conditioned computer rooms with staff to
operate them.
The Batch System was introduced to reduce the wasted time in the computer.
A tray full of jobs was collected in the input room and read into the magnetic
tape. After that, the tape was rewound and mounted on a tape drive. Then the
batch operating system was loaded in which read the first job from the tape
and ran it. The output was written on the second tape. After the whole batch
was done, the input and output tapes were removed and the output tape was
printed.

The Third Generation ( 1965 - 1980 ): Integrated Circuits and


Multiprogramming
Until the 1960’s, there were two types of computer systems i.e the scientific
and the commercial computers. These were combined by IBM in the
System/360. This used integrated circuits and provided a major price and
performance advantage over the second generation systems.
The third generation operating systems also introduced multiprogramming.
This meant that the processor was not idle while a job was completing its I/O
operation. Another job was scheduled on the processor so that its time would
not be wasted.

The Fourth Generation ( 1980 - Present ): Personal Computers


Personal Computers were easy to create with the development of large-scale
integrated circuits. These were chips containing thousands of transistors on a
square centimeter of silicon. Because of these, microcomputers were much
cheaper than minicomputers and that made it possible for a single individual
to own one of them.
The advent of personal computers also led to the growth of networks. This
created network operating systems and distributed operating systems. The
users were aware of a network while using a network operating system and
could log in to remote machines and copy files from one machine to another.
Types of Operating Systems
An Operating System performs all the basic tasks like managing file,process,
and memory. Thus operating system acts as manager of all the resources,
i.e. resource manager. Thus operating system becomes an interface between
user and machine.
Types of Operating Systems: Some of the widely used operating systems are
as follows-
1. Batch Operating System –
This type of operating system does not interact with the computer directly.
There is an operator which takes similar jobs having same requirement and
group them into batches. It is the responsibility of operator to sort the jobs
with similar needs.

Advantages of Batch Operating System:


 It is very difficult to guess or know the time required by any job to
complete. Processors of the batch systems know how long the job would
be when it is in queue
 Multiple users can share the batch systems
 The idle time for batch system is very less
 It is easy to manage large work repeatedly in batch systems
Disadvantages of Batch Operating System:
 The computer operators should be well known with batch systems
 Batch systems are hard to debug
 It is sometime costly
 The other jobs will have to wait for an unknown time if any job fails
Examples of Batch based Operating System: Payroll System, Bank Statements
etc.
2. Time-Sharing Operating Systems –
Each task is given some time to execute, so that all the tasks work smoothly.
Each user gets time of CPU as they use single system. These systems are also
known as Multitasking Systems. The task can be from single user or from
different users also. The time that each task gets to execute is called quantum.
After this time interval is over OS switches over to next task.

Advantages of Time-Sharing OS:


 Each task gets an equal opportunity
 Less chances of duplication of software
 CPU idle time can be reduced
Disadvantages of Time-Sharing OS:
 Reliability problem
 One must have to take care of security and integrity of user programs
and data
 Data communication problem
Examples of Time-Sharing OSs are: Multics, Unix etc.
3. Distributed Operating System –
These types of operating system is a recent advancement in the world of
computer technology and are being widely accepted all-over the world and,
that too, with a great pace. Various autonomous interconnected computers
communicate each other using a shared communication network. Independent
systems possess their own memory unit and CPU. These are referred as loosely
coupled systems or distributed systems. These system’s processors differ in
size and function. The major benefit of working with these types of operating
system is that it is always possible that one user can access the files or
software which are not actually present on his system but on some other
system connected within this network i.e., remote access is enabled within the
devices connected in that network.

Advantages of Distributed Operating System:


 Failure of one will not affect the other network communication, as all
systems are independent from each other
 Electronic mail increases the data exchange speed
 Since resources are being shared, computation is highly fast and durable
 Load on host computer reduces
 These systems are easily scalable as many systems can be easily added
to the network
 Delay in data processing reduces
Disadvantages of Distributed Operating System:
 Failure of the main network will stop the entire communication
 To establish distributed systems the language which are used are not
well defined yet
 These types of systems are not readily available as they are very
expensive. Not only that the underlying software is highly complex and
not understood well yet
Examples of Distributed Operating System are- LOCUS etc.

4. Real-Time Operating System –


These types of OSs serves the real-time systems. The time interval required to
process and respond to inputs is very small. This time interval is called response
time.

Real-time systems are used when there are time requirements are very strict like
missile systems, air traffic control systems, robots etc.
Two types of Real-Time Operating System which are as follows:
 Hard Real-Time Systems:
These OSs are meant for the applications where time constraints are very strict
and even the shortest possible delay is not acceptable. These systems are built
for saving life like automatic parachutes or air bags which are required to be
readily available in case of any accident. Virtual memory is almost never found
in these systems.
 Soft Real-Time Systems:
These OSs are for applications where for time-constraint is less strict.

Advantages of RTOS:
 Maximum Consumption: Maximum utilization of devices and system,thus
more output from all the resources
 Task Shifting: Time assigned for shifting tasks in these systems are very
less. For example in older systems it takes about 10 micro seconds in shifting
one task to another and in latest systems it takes 3 micro seconds.
 Focus on Application: Focus on running applications and less importance to
applications which are in queue.
 Real time operating system in embedded system: Since size of programs
are small, RTOS can also be used in 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 type of
systems.
Disadvantages of RTOS:
 Limited Tasks: Very few tasks run at the same time 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
interrupt signals to response earliest to interrupts.
 Thread Priority: It is not good to set thread priority as these systems are very
less prone to switching tasks.
Examples of Real-Time Operating Systems are: Scientific experiments, medical
imaging systems, industrial control systems, weapon systems, robots, air traffic
control systems, etc.

You might also like