CHAPTER 1:
INTRODUCTION
TO OS
1) What is operating system??
A) The Operating System is a program with the following features −
An operating system is a program that acts as an interface
between the software and the computer hardware.
It is an integrated set of specialized programs used to manage
overall resources and operations of the computer.
It is a specialized software that controls and monitors the
execution of all other programs that reside in the computer,
including application programs and other system software.
OS is a resource allocator.
OS is a control program.it Controls execution of programs to
prevent errors and improper use of the computer
Computer Startup:
bootstrap program is loaded at power-up or reboot.
Typically stored in ROM or EPROM, generally known as
firmware .
Initializes all aspects of system.
Loads operating system kernel and starts execution
Structure of Operating system:
Here are the list of all those five designs or structures of the operating
systems, we will examine.
1. Monolithic Systems
2. Layered Systems
3. Virtual Machines
4. Exokernels
5. Client-Server Systems
Now let's describe briefly about all the above different-different
structures of operating systems.
1. Monolithic Systems
The operating system (OS) is written as a collection of
procedures, each of which can call any of the other ones,
whenever it needs to.
When this technique is used, then each procedure in the system
has a well-defined interface in terms of parameter, and results,
and each one is free to call any of the other ones, if the latter
provides some useful computation that the former needs.
Monolithic systems provides a basic structure for the operating
system.
a main program that invokes the requested service procedure.
a set of service procedures that carry out the system call.
a set of utility procedures that help the service procedure.
In Monolithic system model, there is one service procedure for
each system call, that takes care of it.
The utility procedures do jobs that are needed by several service
procedures, such as fetching the data from the user programs.
This division of the procedures into the following three layers:
1. Main Procedure
2. Service Procedures
3. Utility Procedures
The figure given below shows all the layered provided above in
monolithic system model of operating system.
2. Layered Systems
This system has 6 layers as shown in the table given below.
Layer Function
5 The operator
4 User programs
3 I/O management
2 Operator-process communication
1 Memory and drum management
0 Processor allocation and multiprogramming
Here, are the description provided layer by layer.
Layer 0 - This layer dealt with allocation of the processor,
switching between processes when interrupts occurred or timers
expired
Layer 1 - This layer did the memory management
Layer 2 - This layer handled the communication between each
process and the operator console
Layer 3 - This layer took care of managing the Input/Output
devices and buffering the information streams to and from them
Layer 4 - On this layer, user programs were found
Layer 5 - On this layer, the system operator process was located
3. Virtual Machines
The system originally called CP/CMS, later renamed VM/370,
was based on an astute observation.
That was a time sharing system, provides multiprogramming
and an extended machine with a more convenient interface than
the bare hardware.
The heart of the system known as virtual machine monitor that
runs on the bare hardware and does the multiprogramming,
providing several virtual machines to next layer up as shown in
the given figure.
These virtual machines aren't extended machines, with files and
other nice features.
They are the exact copies of the bare hardware, including the
kernel/user mode, Input/Output, interrupts, and everything else
the real machine has.
4. Exokernels
Exokernels is a program present at the bottom layer, running in
the kernel mode.
The work of exokernel is just to allocate the resources to the
virtual machines and check attempts to use them to make sure no
machine is trying to use some other's resources.
Exokernels saves a layer of mapping which is the advantage of
the exokernel scheme.
5. Client-Server Model
In the client-server model, as shown in the figure given below, all
the kernel does is handle the communication between the clients
and the servers.
By splitting the operating system (OS) up into parts, each of
which only handles one fact of the system, such as file service,
terminal service, process service, or memory service, each part
becomes small and manageable.
The adaptability of the client-server model, to use in distributed
system is the advantage of this model.
Objectives of Operating System
The objectives of the operating system are −
To make the computer system convenient to use in an efficient
manner.
To hide the details of the hardware resources from the users.
To provide users a convenient interface to use the computer
system.
To act as an intermediary between the hardware and its users,
making it easier for the users to access and use other resources.
To manage the resources of a computer system.
To keep track of who is using which resource, granting resource
requests, and mediating conflicting requests from different
programs and users.
To provide efficient and fair sharing of resources among users and
programs.
Characteristics of Operating System
Here is a list of some of the most prominent characteristic features of
Operating Systems −
Memory Management − Keeps track of the primary memory,
i.e. what part of it is in use by whom, what part is not in use, etc.
and allocates the memory when a process or program requests it.
Processor Management − Allocates the processor (CPU) to a
process and deallocates the processor when it is no longer
required.
Device Management − Keeps track of all the devices. This is
also called I/O controller that decides which process gets the
device, when, and for how much time.
File Management − Allocates and de-allocates the resources
and decides who gets the resources.
Security − Prevents unauthorized access to programs and data
by means of passwords and other similar techniques.
Job Accounting − Keeps track of time and resources used by
various jobs and/or users.
Control Over System Performance − Records delays
between the request for a service and from the system.
Interaction with the Operators − Interaction may take place
via the console of the computer in the form of instructions. The
Operating System acknowledges the same, does the
corresponding action, and informs the operation by a display
screen.
Error-detecting Aids − Production of dumps, traces, error
messages, and other debugging and error-detecting methods.
Coordination Between Other Software and Users −
Coordination and assignment of compilers, interpreters,
assemblers, and other software to the various users of the
computer systems.
Operating System | 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. Network Operating System –
These systems run on a server and provide the capability to
manage data, users, groups, security, applications, and other
networking functions.
These type of operating systems allow shared access of files,
printers, security, applications, and other networking functions
over a small private network.
One more important aspect of Network Operating Systems is that
all the users are well aware of the underlying configuration, of all
other users within the network, their individual connections etc.
and that’s why these computers are popularly known as tightly
coupled systems.
Advantages of Network Operating System:
Highly stable centralized servers
Security concerns are handled through servers
New technologies and hardware up-gradation are easily
integrated to the system
Server access are possible remotely from different locations and
types of systems
Disadvantages of Network Operating System:
Servers are costly
User has to depend on central location for most operations
Maintenance and updates are required regularly
Examples of Network Operating System are: Microsoft
Windows Server 2003, Microsoft Windows Server 2008, UNIX, Linux,
Mac OS X, Novell NetWare, and BSD etc.
5. 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.
Difference between single processor and multi
processor
SINGLE PROCESSOR MULTI PROCESSOR
1. It contains only one 1. It contains two or more
processor processors
1. These systems use different 2. These have many
controllers for completing processors that can perform
special tasks such as DMA different tasks.This can be
controller done in symmetric or
Asymmetric multi
processing
3. These are more expensive 3.Less expensive because n
compared to multi processor multiprocessor
processor system systems is available,it is
cheaper than n different single
multiprocessor systems.
4. Easy to design a single 4.Designing a multi processor
processor because all the system is quite complicated
Processors in multi than single processor systems.
processor systems need to
be synchronized and this
can be quite complicated
5. Throughput of single 5.Throughput of
processor systems is less multiprocessor systems is
than multiprocessor more than single processor
systems systems.
6. Less reliable 6.More reliable.
7. Most modern computers 7.Multi processor systems are
are Single processor used only in niche systems.
systems
single processor systems Multi processor systems
Operating System – Services
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.
Introduction to System Calls
To understand system calls, first one needs to understand the difference
between kernel mode and user mode of a CPU. Every modern
operating system supports these two modes.
Modes supported by the operating system
Kernel Mode
When CPU is in kernel mode, the code being executed can access
any memory address and any hardware resource.
Hence kernel mode is a very privileged and powerful mode.
If a program crashes in kernel mode, the entire system will be halted.
User Mode
When CPU is in user mode, the programs don't have direct access to
memory and hardware resources.
In user mode, if any program crashes, only that particular program is
halted.
That means the system will be in a safe state even if a program in user
mode crashes.
Hence, most programs in an OS run in user mode.
System Call
When a program in user mode requires access to RAM or a
hardware resource, it must ask the kernel to provide access to that
resource. This is done via something called a system call.
When a program makes a system call, the mode is switched from
user mode to kernel mode. This is called a context switch.
System call provides the services of the operating system to the
user programs via Application Program Interface(API).
Then the kernel provides the resource which the program
requested. After that, another context switch happens which
results in change of mode from kernel mode back to user mode.
Generally, system calls are made by the user level programs in the
following situations:
Creating, opening, closing and deleting files in the file system.
Creating and managing new processes.
Creating a connection in the network, sending and receiving packets.
Requesting access to a hardware device, like a mouse or a printer.
System call parameters
Three general methods exist for passing parameters to the OS:
1. Parameters can be passed in registers.
2. When there are more parameters than registers, parameters can be
stored in a block and the block address can be passed as a parameter
to a register.
3. Parameters can also be pushed on or popped off the stack by the
operating system.
Types of System Calls
There are mainly five types of system calls. These are explained in
detail as follows:
Here are the types of system calls:
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
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()
GetCurrentProcessID() getpid()
Information Maintenance SetTimer() alarm()
Sleep() sleep()
CreatePipe() pipe()
Communication CreateFileMapping() shmget()
MapViewOfFile() mmap()
Some of the examples of all the above types of system calls in Windows
and Unix are given as follows:
There are many different system calls as shown above. Details of some of
those system calls are as follows:
wait()
In some systems, a process may wait for another process to complete its
execution. This happens when a parent process creates a child process
and the execution of the parent process is suspended until the child
process executes. The suspending of the parent process occurs with a
wait() system call. When the child process completes execution, the
control is returned back to the parent process.
exec()
This system call runs an executable file in the context of an already
running process. It replaces the previous executable file. This is known
as an overlay. The original process identifier remains since a new process
is not created but data, heap, stack etc. of the process are replaced by the
new process.
fork()
Processes use the fork() system call to create processes that are a copy of
themselves. This is one of the major methods of process creation in
operating systems. When a parent process creates a child process and the
execution of the parent process is suspended until the child process
executes. When the child process completes execution, the control is
returned back to the parent process.
exit()
The exit() system call is used by a program to terminate its execution. In
a multithreaded environment, this means that the thread execution is
complete. The operating system reclaims resources that were used by the
process after the exit() system call.
kill()
The kill() system call is used by the operating system to send a
termination signal to a process that urges the process to exit.However,
kill system call does not necessary mean killing the process and can have
various meanings.