Operating Systems
Operating Systems
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.
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.
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
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.
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.
Advantages
Interactivity
Interactivity refers to the ability of users to interact with a computer system.
An Operating system does the following activities related to interactivity −
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
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 −
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.
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 −
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 −
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 −
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:
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:
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:
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.