Os Unit 1
Os Unit 1
MODULE 1
CHAPTER 1: INTRODUCTION
The basic hardware components comprises of CPU, memory, I/O devices. The application program
uses these components. The OS controls and co-ordinates the use of hardware, among various
application programs (like compiler, word processor etc.) for various users.
Page
OPERATING
The OS allocates the resources among the programs such that the hardware is efficiently used.
The operating system is the program running at all the times on the computer. It is usually called as the
kernel.
Views of OS
Operating System can be viewed from two viewpoints: User view and System view
1 User View: The user's view of the OS depends on the type of the user
If the user is using standalone system, then OS is designed for ease of use and high performances.
Here resource utilization is not given importance.
If the users are at different terminals connected to a mainframe or minicomputers, by sharing
information and resources, then the OS is designed to maximize resource utilization. OS is
designed such that the CPU time, memory and I/O are used efficiently and no single user takes
more than the resource allotted to them
If the users are in workstations, connected to networks and servers, then the user have a dedicated
resources but also share resources such as networking and servers-files, print servers. Here the OS
is designed for both ease of use and resource availability (files).
Users of hand held systems, expects the OS to be designed for ease of use and performance per
amount of battery life.
Other systems like embedded systems used in home devices (like washing m/c) and automobiles
do not have any user interaction. They are connected to network either directly by wire or through
wireless modems and networking.
Resource allocator: The OS acts as a manager of hardware and software resources.(CPU time,
memory space, file-storage space, I/O devices, shared files etc. are the different resources required
during execution of a program) There can be conflicting request for these resources by different
programs running in same system. The OS assigns the resources to the requesting program
depending on the priority. Resource allocation is important when many users access the same
computer
Control Program: The OS is a control program and manage the execution of user program to
prevent errors and improper use of the computer. It is concerned with the operation and control of
I/O devices
1 Mainframe Systems: It is the system where the first computer used to handle many commercial
scientific applications. The growth of mainframe systems traced from simple batch system-where
the computer runs one and only one application to time shared system-which allowed for user
interaction with the computer system
Batch /Early System: Early computers were physically large machine. The common input
devices were card readers, tape drivers. The common output devices were line printers, tape
Page
OPERATING
drivers and card punches. In these systems the user did not interact directly with the computer
system. Instead the user used to prepare a job which consists of programming data and some
control information and then submitted it to the computer operator, after some time the output
appeared. The output in these early computer was fairly simple. But the main task was to transfer
the control automatically from one job to next. The operating system always resides in the
memory. To speed up processing, operators batched the jobs with similar needs and run together
as a group. The memory layout is shown in figure 2
The disadvantages of batch system: Execution environment of the CPU is often idle because the
speed up of I/O devices is much slower than the CPU.
Page
OPERATING
4 Multiprocessor Systems (Parallel systems or Tightly coupled systems): These systems have two
or more processors in close communication, sharing the computer bus, the clock, memory, and
peripheral devices.
Multiprocessor systems have three main advantages:
Increased Throughput: Throughput is defined as number of processes computed per unit time.
By increasing the number of processors, the more work can be done in less time. In
multiprocessor system, execution of different programs take place simultaneously. Even if the
number of processors is increased the performance cannot be simultaneously increased. This
is due to the overhead incurred in keeping all the parts working correctly. The speed-up ratio
with N processors is not N, rather, it is less than N. Thus the speed of the system is not has
expected.
Economy of Scale: Multiprocessor systems can cost less than equivalent multiple single-
processor systems. As the multiprocessor systems share peripherals, mass storage, and power
Page
OPERATING
supplies, the cost of implementing this system is economical. If several processes are working
on the same data, the data can also be shared among them
Increased reliability: In multiprocessor systems, functions are shared among several
processors. If one processor fails, the system is not halted, it only slows down. The job of the
failed processor is taken up, by other processors. This ability to continue to operate in spite of
failure makes the system fault tolerant. Fault tolerance requires a mechanism to allow the
failure to be detected, diagnosed, and, if possible, corrected.
There are two types of multiprocessor systems
i Asymmetric Multiprocessing (Master-Slave Architecture) : Here each processor is
assigned a specific task, by the master processor. A master processor controls the other
processors in the system. It schedules and allocates work to the slave processors. This scheme
defines master-slave relationship.
Ex- Sun's Operating system : SUNOS version 4
ii Symmetric multiprocessing (SMP): The processors are considered as peers; no master-slave
relationship exists between processors. Each processor performs all tasks within the OS. All
the processors have its own registers and CPU, only memory is shared as shown in figure 4
The benefit of this model is that many processes can run simultaneously. N processes can run if
there are N CPUs—without causing a significant deterioration of performance. Operating systems
like Windows, Windows XP, Mac OS X, and Linux—now provide support for SMP.
Page
OPERATING
A wide-area network (WAN) usually links buildings, cities, or countries. A global company may
have a WAN to connect its offices worldwide.
A metropolitan-area network (MAN) links buildings within a city
A small-area network connects systems within a several feet using wireless technology. Eg.
Bluetooth and 802.11.
The media to carry networks include copper wires, fibre strands, and wireless transmissions
between satellites, microwave dishes, and radios
A network operating system is an operating system that provides features such as file sharing
across the network and that includes a communication scheme that allows different processes on
different computers to exchange messages.
Advantage:
Resource sharing, computation speed up, reliability, communication.
A distributed OS provides a less autonomous environment: The different operating systems
communicate closely enough to provide the illusion that only a single OS controls the network
6 Real-Time Systems: Real time system is used when there are rigid time requirements on the
operation of a processor or flow of data.
The OS of real-time embedded systems provide limited features. No user interface.
Embedded systems always run real-time Operating Systems
Sensors bring data to the computers. The computer analyses data and adjust the controls to modify
the sensor inputs.
A real time OS has well defined fixed time constraints. Processing must be done within the time
constraint or the system will fail. A real time system is said to function correctly only if it returns
the correct result within the time constraint. These systems are characterized by having time as a
key parameter
Ex: System that controls scientific experiments, medical imaging systems and some display
systems are real time systems
Disadvantage:
A real time system is considered to function correctly only if it returns the correct result within
the time constraints
Secondary storage is limited or missing, instead data is usually stored in short term memory or
ROM
Advanced OS features are absent.
Real time system is of two types:
Hard real time systems: It guarantees that the critical task has been completed on time. The
sudden task is taken place at a sudden instant of time.
Soft real time systems: It is a less restrictive type of real time system where a critical task gets
priority over other tasks and retains that priority until it computes. These have more limited
utility than hard real time systems. Digital audio or multimedia is included in this category.
Page
OPERATING
1. Process Management
2. Memory Management
Main memory is a large array of words or bytes. Each word or byte has its own address.
Main memory is the storage device which can be easily and directly accessed by the CPU.
The central processor reads instructions from main memory during the instruction-fetch cycle and also
reads and writes data from main memory during data-fetch cycle.
To improve both the utilization of the CPU and the speed of the computer's response to its users,
general-purpose computers must keep several programs in memory, creating a need for memory
management.
The OS is responsible for the following activities in connection with memory management:
Keeping track of which parts of memory are currently being used by user.
Deciding which processes and data to move into and out of memory.
Allocating and deallocating memory space as needed.
3. Storage Management
Page
OPERATING
File-System Management
Main memory is too small to accommodate all data and programs, and as the data that it holds are
erased when power is lost, the computer system must provide secondary storage to back up main
memory.
Most modern computer systems use disks as the storage medium for both programs and data.
Most programs including compilers, assemblers, word processors, editors, and formatters are stored on
a disk until loaded into memory and then use the disk as both the source and destination of their
processing.
Hence, the proper management of disk storage is of central importance to a computer system.
The operating system is responsible for the following activities in connection with disk management:
Free-space management
Storage allocation
Disk scheduling
As the secondary storage is used frequently, it must be used efficiently.
The entire speed of operation of a computer may depend on the speeds of the disk.
Magnetic tape drives and their tapes, CD, DVD drives and platters are tertiary storage devices.
The functions that operating systems provides include mounting and unmounting media in devices,
allocating and freeing the devices for exclusive use by processes, and migrating data from secondary to
tertiary storage.
Page
OPERATING
Caching
In a Multiprocessor environment, in addition to maintaining internal registers, each of the CPUs also
contains a local cache. In such an environment, a copy of A may exist simultaneously in several
caches. Since the various CPUs can all execute concurrently, any update done to the value of A in one
cache is immediately reflected in all other caches where A resides. This situation is called cache
coherency, and it is usually a hardware problem (handled below the operating-system level).
I/O Systems
One of the purposes of an OS is to hide the peculiarities of specific hardware devices from the user.
The I/O subsystem consists of several components:
A memory-management component that includes buffering, caching, and spooling
A general device-driver interface
Drivers for specific hardware devices
Page
OPERATING
Only the device driver knows the peculiarities of the specific device to which it is assigned.
If a computer system has multiple users and allows the concurrent execution of multiple processes,
then access to data must be regulated. Hence, a proper authorization has to be given by the OS for each
user
Protection is a mechanism for controlling the access of processes or users to the resources defined by
a computer system. This mechanism must provide means for specification of the controls to be
imposed and means for enforcement.
Protection improves reliability. A protection-oriented system provides a means to distinguish between
authorized and unauthorized usage.
A system can have adequate protection but still be prone to failure and allow inappropriate access.
Consider a user whose authentication information is stolen. His/her data could be copied or deleted,
even though file and memory protection are working. It is the job of security to defend a system from
external and internal attacks. Such attacks spread across a huge range and include viruses and worms,
denial-of service attacks etc.
Protection and security require the system to be able to distinguish among all its users.
Most OS maintain a list of user names and associated user identifiers (user IDs). When a user logs in
to the system, the authentication stage determines the appropriate user ID for the user.
Group functionality can be implemented with list of group names and group identifiers. A user can be
in one or more groups, depending on OS.
An operating system provides an environment for the execution of programs. It provides certain
services to programs and to the users of those programs.
The specific services provided, differ from one OS to another
The figure 6 shows one view of the OS service
Page
OPERATING
OS provide services (functions) that are helpful to the user, which includes:
User Interface: Means by which users can issue commands to the system. Depending on the
operating system these may be a DTrace command-line interface (CLI), a Graphical User
Interface (GUI) or a Batch Command Interface.
In Command Line Interface(CLI)- commands are given to the system. In Batch interface-
commands and directives to control these commands are entered in a file and then the file is
executed. In GUI systems- windows with pointing device to get inputs and keyboard to enter the
text.
Program Execution: The OS must be able to load a program into memory, run the program, and
terminate the program, either normally or abnormally.
I/O Operations: The OS is responsible for transferring the data to and from I/O devices,
including keyboards, terminals, printers, and files. For specific devices, special functions (device
drivers) are provided by OS.
File-System Manipulation: Programs need to read and write files or directories. The services
required to create or delete files, search for a file, list the contents of a file and change the file
permissions are provided by OS.
Error Detection: Both hardware and software errors must be detected and handled
appropriately by the OS. Errors may occur in the CPU and memory hardware (such as
power failure and memory error), in I/O devices (such as a parity error on tape, a connection
failure on a network, or lack of paper in the printer), and in the user program (such as an
arithmetic overflow, an attempt to access an illegal memory location).
OS also provide services (functions) for the efficient operation of the system, which includes:
Resource Allocation: Resources like CPU cycles, main memory, storage space, and I/O devices
must be allocated to multiple users and multiple jobs at the same time. The OS provide CPU-
scheduling routines that take into account the speed of the CPU, the jobs that must be executed,
the number of registers available etc.
Accounting: There are services in OS to keep track of system activity and resource usage, either
for billing purposes or for statistical record keeping that can be used to optimize future
performance.
Page
OPERATING
Protection and Security: The owners of information (file) in multiuser or networked computer
system may want to control the use of that information. When several separate processes execute
concurrently, one process should not interfere with other or with OS.
Protection involves ensuring that all access to system resources is controlled.
Security of the system from outsiders must also be done, by means of a password in order to
authenticate the user.
For this, the program need names of two files: input file and output file. These names can be provided
in many ways.
One approach: In interactive system, a sequence of system calls are required. First, to write a message
on the screen and then to accept the input filename from keyboard
Second approach: In mouse-based and icon-based systems, a menu of filenames is displayed on the
screen. Then the user can use the mouse to select the source name and the destination name
When the program tries to open the input file, it may find that there is no file of that name or that the
file is protected against access. In these cases, the program should print a message on the
console(another system call) and then terminate abnormally (another system call).
If input file exists, then create a new output file (another system call). In this situation, we may find
that there is already an output file with the same name, which cause the program to abort (a system
call), or may delete the existing file (another system call) and create a new one (another system call)
Nandini S, Dept. of CSE
GITAM Uni ersit Bengal r Page
OPERATING
Now that both the files are opened, we enter a loop that reads from the input file(another system call)
and writes to output file (another system call).
Finally, after the entire file is copied, the program may close both files (another system call), write a
message to the console or window(system call), and finally terminate normally (final system call).
Most programmers do not use the low-level system calls directly, but instead use an "Application
Programming Interface", API.
The API specifies a set of functions that are available to an application programmer, including the
parameters that are passed to each function and the return values the programmer can expect
The APIs instead of direct system calls provides for greater program portability between different
systems. The API then makes the appropriate system calls through the system call interface, using a
system call table to access specific numbered system calls, as shown in Figure 8
Typically, a number is associated with each system call, and the system-call interface maintains a table
indexed according to these numbers
The system call table (consisting of system call number and address of the particular service) invokes a
particular service routine for a specific system call.
The caller need know nothing about how the system call is implemented or what it does during
execution.
Figure 8: The handling of a user application invoking the open( ) system call
Page
OPERATING
A collection of programs that provide a convenient environment for program development and
execution (other than OS) are called system programs or system utilities.
It is not a part of Kernel or command interpreters
System programs are divided into following categories:
File Management: These programs create, delete, copy, rename, print & manipulate files and
directories
Status Information: Utilities to check on the date, time, number of users, processes running, data
logging, etc. System registries are used to store and recall configuration information for particular
applications.
File Modification: Text editors are available to create and modify the contents of file stored on
disk. Special commands can also be used to search contents of files or perform text manipulation
on files
Programming-Language Support: Compliers, assemblers & interpreters are provided to the user
with the OS
Program loading and Execution: Once a program is assembled or compiled, it must be loaded
into memory to be executed. The OS provide absolute loaders, relocatable loaders, linkage editors,
overlay loaders etc
Communications: Programs provide the mechanism for creating virtual connections among
processors, users, and computer systems. It also includes sending electronic mail messages, to
browse web page, remote logins, file transfers, and remote command execution
Application Programs: Most OS provide programs that are useful to solve common problems or
to perform common operations. Ex: web browsers, word processors & text formatters etc.
The view of the OS seen by most users is defined by the application and system programs, rather than
by actual system calls
Page
OPERATING
OS structure must be carefully designed. The task of OS is divided into small components and then
interfaced to work together.
1) Simple Structure
Many operating systems do not have well-defined structures. They started as small, simple, and
limited systems and then grew beyond their original scope. Eg: MS-DOS.
In MS-DOS, the interfaces and levels of functionality are not well separated as shown in Figure 10
Application programs can access basic I/O routines to write directly to the display and disk drives.
Such freedom leaves MS-DOS in bad state and the entire system can crash down when user
programs fail.
UNIX OS consists of two separable parts: the kernel and the system programs. The kernel is
further separated into a series of interfaces and device drivers.
But the traditional UNIX operating System is layered as shown in Figure 11.
Everything below the system-call interface and above the physical hardware is the kernel.
The kernel provides the file system, CPU scheduling, memory management, and other operating-
system functions through system calls
Page
OPERATING
2) Layered Approach
The OS is broken into number of layers (levels). Each layer rests on the layer below it, and relies
on the services provided by the next lower layer.
Bottom layer(layer 0) is the hardware and the topmost layer (layer N) is the user interface as
shown in Figure 12
A typical layer, consists of data structure and routines that can be invoked by higher-level layer.
Under a top-down approach, the overall functionality and features are determined and are
separated into components.
A OS layer is an implementation of an abstract object made up of data and the operations that can
manipulate those data
Advantages:
Simplicity of construction and debugging
The layers are selected such that each uses functions and services of only lower-level layers.
Hence simplifies debugging and system verification i.e., the first layer can be debugged without
concerning the rest of the system. Once the first layer is debugged, its correct functioning is
assumed while the 2nd layer is debugged & so on.
If an error is found during the debugging of a particular layer, the error must be on that layer
because the layers below it are already debugged. Thus the design & implementation of the
system are simplified when the system is broken down into layers.
A layer doesn‘t need to know how these operations are implemented; it only needs to know
what these operations do.
Disadvantages:
The various layers must be appropriately defined, as a layer can use only lower level layers.
Less efficient than other types, because any interaction with layer 0 required from top layer.
The system call should pass through all the layers and finally to layer 0. This is an overhead.
Page
OPERATING
3) Microkernels
The basic idea behind micro kernels is to remove all non-essential services from the kernel, thus
making the kernel as small and efficient as possible.
The removed services are implemented as system applications(user space)
Most microkernels provide basic process and memory management, and message passing between
other services.
Benefit: To provide communication facility between the client program and the various services
that are running in user space. Communication is provided by message passing
Mach was the first and most widely known microkernel, and now forms a major component of
Mac OS X.
Advantages:
System expansion can be easier, because it only involves adding more system applications, not
rebuilding a new kernel.
When the kernel does not have to be modified, the changes are fewer, because the microkernel
is a smaller kernel
Hence microkernel is smaller kernel
The microkernel OS is easier to port from one hardware design to another
Provides more security and reliability, since most services are running as user programs rather
than kernel processes.
Disadvantages:
Performance is reduced due to increased system function overhead
4) Modules
Modern OS development is object-oriented, with a relatively small core kernel and a set of
modules which can be linked in dynamically.
Page
OPERATING
For Example: The Solaris OS structure shown in figure 13 is organized around a core kernel with
7 types of loadable kernel modules:
Scheduling Classes
File Systems
Loadable System calls
Executable formats
STREAMS modules
Miscellaneous
Device and bus drivers
Modules are similar to Layered systems in that each subsystem has clearly defined tasks and
interfaces, but any module is free to contact any other module, eliminating the problems of going
through multiple intermediary layers
The kernel is relatively small in this architecture, similar to microkernels, but the kernel does not
have to implement message passing since modules are free to contact each other directly. Eg:
Solaris, Linux and Mac OS X
The Apple Mac OS X Operating system uses a hybrid structure. It is a layered system in which
one layer consists of the Mach microkernel as shown in Figure 14
Page
OPERATING
Below these layers is the kernel environment, which consists primarily of the Mach microkernel and
the BSD kernel.
Mach provides memory management, support for remote procedure calls (RPCs) and interprocess
communication (IPC) facilities.
The BSD component provides a BSD command line interface, support for networking and file systems
etc.
Advantages:
Resembles a layered system, in which a module can call any other module
Resembles microkernel approach, in which primary module has only core functions and
knowledge of how to load and communicate with other modules; but it is more efficient, because
modules do not need to invoke message passing in order to communicate
Page