OS Module - 1
OS Module - 1
Module I
INTRODUCTION TO OPERATING SYSTEM
The basic hardware components comprise 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 (Fig. 1.1).
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. Kernel functions are used always in system, so always stored in memory. Non-kernel
functions are stored in hard disk, and it is retrieved whenever required.
1.3 Views of
OS
1. User Views: -
The user’s view of the operating system depends on the type of user.
i. 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.
iii. If the users are in workstations, connected to networks and servers, then the user have
a system unit of their own and shares resources and files with other systems. Here the
OS is designed for both ease of use and resource availability (files).
iv. Users of hand-held systems, expects the OS to be designed for ease of use and
performance per amount of battery life.
v. Other systems like embedded systems used in home devices (like washing m/c) &
automobiles do not have any user interaction. There are some LEDs to show the status
of its work.
2. System Views: -
Operating system can be viewed as a resource allocator and control program.
i. 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
III SEMESTER OPERATING SYSTEM 2
(BCS303)
RV Institute of Technology &
Management®
OPERATING SYSTEMS Module I
When system is switched on, ‘Bootstrap’ program is executed. It is the initial program to run in
the system. This program is stored in read-only memory (ROM) or in electrically erasable
programmable read-only memory (EEPROM). It initializes the CPU registers, memory, device
controllers and other initial setups. The program also locates and loads, the OS kernel to the
memory. Then the OS starts with the first process to be executed (ie. ‘init’ process) and then wait
for the interrupt from the user.
be from the hardware or the software. Hardware may trigger an interrupt at any time by sending
a signal to the CPU. Software triggers an interrupt by executing a special operation called a
system call (also called a monitor call).
When the CPU is interrupted, it stops what it is doing and immediately transfers
execution to a fixed location. The fixed location (Interrupt Vector Table) contains the starting
address where the service routine for the interrupt is located. After the execution of interrupt
service routine, the CPU resumes the interrupted computation.
Interrupts are an important part of computer architecture. Each computer design has its
own interrupt mechanism, but several functions are common. The interrupt must transfer control
to the appropriate interrupt service routine
Processor
interrupt
IVT
Interrupt Service
Routine
Stored at a fixed
location
Fig. 1.3 Interrupt time line for a single process doing output.
Storage Structure
Computer programs must be in main memory (RAM) to be executed. Main memory is the large
memory that the processor can access directly. It commonly is implemented in a semiconductor
technology called dynamic random-access memory (DRAM). Computers provide Read Only
Memory (ROM), whose data cannot be changed.
All forms of memory provide an array of memory words. Each word has its own address.
Interaction is achieved through a sequence of load or store instructions to specific memory
addresses.
A typical instruction-execution cycle, as executed on a system with a Von Neumann
architecture, first fetches an instruction from memory and stores that instruction in the
instruction register. The instruction is then decoded and may cause operands to be fetched from
memory and stored in some internal register. After the instruction on the operands has been
executed, the result may be stored back in memory.
Ideally, we want the programs and data to reside in main memory permanently. This
arrangement usually is not possible for the following two reasons:
1. Main memory is usually too small to store all needed programs and data permanently.
2. Main memory is a volatile storage device that loses its contents when power is turned
off.
The wide variety of storage systems in a computer system can be organized in a hierarchy
as shown in the Fig., according to speed, cost and capacity. The higher levels are expensive, but
they are fast. As we move down the hierarchy, the cost per bit generally decreases, whereas the
access time and the capacity of storage generally increases.
In addition to differing in speed and cost, the various storage systems are either volatile or
nonvolatile. Volatile storage loses its contents when the power to the device is removed. In the
absence of expensive battery and generator backup systems, data must be written to nonvolatile
storage for safekeeping. In the hierarchy shown in Fig., the storage systems above the electronic
disk are volatile, whereas those below are nonvolatile.
its importance to the reliability and performance of a system and because of the varying nature
of the devices.
Every device has a device controller, maintains some local buffer and a set of special-
purpose registers. The device controller is responsible for moving the data between the peripheral
devices. The operating systems have a device driver for each device controller.
To start an I/O operation, the device driver loads the registers within the device controller.
The device controller, examines the contents of these registers to determine what action to take
(such as "read a character from the keyboard").
The controller starts the transfer of data from the device to its local buffer. Once the
transfer of data is complete, the device controller informs the device driver (OS) via an interrupt
that it has finished its operation. The device driver then returns control to the operating system,
and also returns the data. For other operations, the device driver returns status information.
This form of interrupt-driven I/O is fine for moving small amounts of data, but very difficult for bulk
data movement. To solve this problem, direct memory access (DMA) is used (Fig. 1.5).
DMA is used for high-speed I/O devices, able to transmit information at close to
memory speeds
Device controller transfers blocks of data from buffer storage directly to main memory
without CPU intervention
Only one interrupt is generated per block, rather than the one interrupt per byte
All special-purpose processors run limited instructions and do not run user processes.
These are managed by the operating system, the operating system sends them information about
their next task and monitors their status.
For example, a disk-controller processor, implements its own disk queue and scheduling
algorithm, thus reducing the task of main CPU. Special processors in the keyboard, converts the
keystrokes into codes to be sent to the CPU.
The use of special-purpose microprocessors is common and does not turn a single-
processor system into a multiprocessor. If there is only one general-purpose CPU, then the system
is a single-processor system.
2. Economy of scale - Multiprocessor systems can cost less than equivalent number of many
single-processor systems. As the multiprocessor systems share peripherals, mass storage,
and power supplies, the cost of implementing this system is economical. If
severalprocesses are working on the same data, the data can also be shared among them.
fails other process will take up its work and the system goes down slowly.
Fault tolerant – When one processor fails, its operations are stopped, the system
failure is then detected, diagnosed, and corrected.
The HP Nonstop system uses both hardware and software duplication to ensure continued
operation despite faults. The system consists of multiple pairs of CPUs. Both processors
in the pair execute same instruction and compare the results. If the results differ, then one
CPU of the pair is at fault, and both are halted. The process that was being executed is
then moved to another pair of CPUs, and the instruction that failed is restarted. This
solution is expensive, since it involves special hardware and considerable hardware
duplication.
2) Symmetric multiprocessing (SMP) – All the processors are considered as peers. There
is no master-slave relationship. All the processors have its own registers and CPU, only
memory is shared.
The benefit of this model is that many processes can run simultaneously as shown in Fig.
1.6 a. 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.
A recent trend in CPU design is to include multiple compute cores on a single chip (Fig. 1.6 b).
The communication between processors within a chip is faster than communication between two
single processors.
In asymmetric clustering – one system is in hot-standby mode while the others are
running the applications. The hot-standby host machine does nothing but monitor the active
server. If that server fails, the hot-standby host becomes the active server.
In symmetric clustering – two or more systems are running applications, and are
monitoring each other. This mode is more efficient, as it uses all of the available hardware. If any
system fails, its job is taken up by the monitoring system.
Other forms of clusters include parallel clusters and clustering over a wide-area network (WAN).
Parallel clusters allow multiple hosts to access the same data on the shared storage. Cluster
technology is changing rapidly with the help of SAN (storage-area networks). Using SAN
resources can be shared with dozens of systems in a cluster, that are separated by miles.
The operating system keeps several jobs in memory simultaneously as shown in Fig. This set of
jobs is a subset of the jobs kept in the job pool. Since the number of jobs that can be kept
simultaneously in memory is usually smaller than the number of jobs that can be kept in the job
pool (in secondary memory). The operating system picks and begins to execute one of the jobs in
memory.
Eventually, the job may have to wait for some tasks, such as an I/O operation, to complete. In a
non-multiprogrammed system, the CPU would sit idle. In a multiprogrammed system, the
operating system simply switches to, the CPU is switched to another job, and so on.
Eventually, the first job finishes waiting and gets the CPU back. Thus, the CPU is never idle.
Multiprogrammed systems provide an environment in which the various system resources (for
example, CPU, memory, and peripheral devices) are utilized effectively, but they do not provide
for user interaction with the computer system
In Time sharing (or multitasking) systems, a single CPU executes multiple jobs by
switching among them, but the switches occur so frequently that the users can interact with each
program while it is running. The user feels that all the programs are being executed at the same
time. Time sharing requires an interactive (or hands-on) computer system, which provides direct
communication between the user and the system. The user gives instructions to the operating
system or to a program directly, using a input device such as a keyboard or a mouse, and waits
for immediate results on an output device. Accordingly, the response time should be short—
typically less than one second
A time-shared operating system allows many users to share the computer simultaneously.
As the system switches rapidly from one user to the next, each user is given the impression that
the entire computer system is dedicated to his use only, even though it is being shared among
many users.
A multiprocessor system is a computer system having two or more CPUs within a single
computer system, each sharing main memory and peripherals. Multiple programs are executed by
multiple processors parallel.
nodes, and the transport media. TCP/IP is the most common network protocol. Most operating
systems support TCP/IP.
Networks are characterized based on the distances between their nodes. A local-area network
(LAN) connects computers within a room, a floor, or a building. 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. E.g.
Bluetooth and 802.11. The media to carry networks also vary - copper wires, fiber strands, and
wireless transmission between satellites, microwave dishes, and radios.
A network operating system is an operating system that provides features such as filesharing
across the network and that allows different processes on different computers to exchange
messages. A computer running a network operating system acts autonomously from all other
computers on the network, although it is aware of the network and is able to communicate with
other networked computers.
Modern operating systems are interrupt driven. If there are no processes to execute, no
I/O devices to service, and no users to whom to respond, an operating system will sit quietly,
waiting for something to happen. Events are signaled by the occurrence of an interrupt or a trap.
Since the operating system and the user programs share the hardware and software resources
of the computer system, it has to be made sure that an error in a user program cannot cause
problems to other programs and the Operating System running in the system.
The approach taken is to use a hardware support that allows us to differentiate among various
modes of execution.
At system boot time, the hardware starts in kernel mode. The operating system is then loaded and
starts user applications in user mode. Whenever a trap or interrupt occurs, the hardware switches
from user mode to kernel mode (that is, changes the mode bit from 1 to 0). Thus, whenever the
operating system gains control of the computer, it is in kernel mode.
The dual mode of operation provides us with the means for protecting the operating
system from errant users—and errant users from one another.
The hardware allows privileged instructions to be executed only in kernel mode. If an
attempt is made to execute a privileged instruction in user mode, the hardware does not execute
the instruction but rather treats it as illegal and traps it to the operating system. The instruction to
switch to user mode is an example of a privileged instruction.
Initial control is within the operating system, where instructions are executed in kernel
mode. When control is given to a user application, the mode is set to user mode. Eventually,
control is switched back to the operating system via an interrupt, a trap, or a system call.
a) Timer
Operating system uses timer to control the CPU. A user program cannot hold CPU for a
long time, this is prevented with the help of timer.
A timer can be set to interrupt the computer after a specified period. The period may be
fixed (for example, 1/60 second) or variable (for example, from 1 millisecond to 1 second).
Fixed timer – After a fixed time, the process under execution is interrupted.
Variable timer – Interrupt occurs after varying interval. This is implemented using a fixed-rate
clock and a counter. The operating system sets the counter. Every time the clock ticks, the
counter is decremented. When the counter reaches 0, an interrupt occurs.
Before changing to the user mode, the operating system ensures that the timer is set to interrupt.
If the timer interrupts, control transfers automatically to the operating system, which may treat
the interrupt as a fatal error or may give the program more time.
The program stored on a disk is a passive entity and the program under execution is an
active entity. A single-threaded process has one program counter specifying the next
instruction to execute. The CPU executes one instruction of the process after another, until the
process completes. A multithreaded process has multiple program counters, each pointing to the
next instruction to execute for a given thread.
The operating system is responsible for the following activities in connection with process
management:
Scheduling process and threads on the CPU
Creating and deleting both user and system processes
Suspending and resuming processes
Providing mechanisms for process synchronization
Providing mechanisms for process communication
The operating system 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.
File management is one of the most visible components of an operating system. Computers can
store information on several different types of physical media. Magnetic disk, optical disk, and
magnetic tape are the most common. Each of these media has its own characteristics and physical
organization. Each medium is controlled by a device, such as a disk drive or tape drive, that also
has its own unique characteristics.
The operating system implements the abstract concept of a file by managing mass storage
media. Files are normally organized into directories to make them easier to use. When multiple
users have access to files, it may be desirable to control by whom and in what ways (read, write,
execute) files may be accessed.
The operating system is responsible for the following activities in connection with file
management:
Creating and deleting files
Creating and deleting directories to organize files
Supporting primitives for manipulating files and directories
Mapping files onto secondary storage
Backing up files on stable (nonvolatile) storage media
As the 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.
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.
1.11.3 Caching
Because caches have limited size, cache management is an important design problem. Careful
selection of the cache size and page replacement policy can result in greatly increased
performance.
The movement of information between levels of a storage hierarchy may be either explicit or
implicit, depending on the hardware design and the controlling operating-system software.
For instance, data transfer from cache to CPU and registers is usually a hardware function,
with no operating-system intervention. In contrast, transfer of data from disk to memory is
usually controlled by the operating system.
In a hierarchical storage structure, the same data may appear in different levels of the
storage system. For example, suppose to retrieve an integer A from magnetic disk to the
processing program. The operation proceeds by first issuing an I/O operation to copy the disk
block on which A resides to main memory. This operation is followed by copying A to the cache
and to an internal register. Thus, the copy of A appears in several places: on the magnetic disk, in
main memory, in the cache, and in an internal register (Fig. 1.9).
One of the purposes of an operating system 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
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. For that purpose, there are mechanisms which
ensure that files, memory segments, CPU, and other resources can be operated on by only those
processes that have gained proper authorization from the operating system.
For example, memory-addressing hardware ensures that a process can execute only
within its own address space. The timer ensures that no process can gain control of the CPU for a
long time. Device-control registers are not accessible to users, so the integrity of the various
peripheral devices is protected.
Distributed system is a collection of systems that are networked to provide the users with
access to the various resources in the network. Access to a shared resource increases computation
speed, functionality, data availability, and reliability.
A network is a communication path between two or more systems. Networks vary by the
protocols used (TCP/IP, UDP, FTP etc.), the distances between nodes, and the transport media
(copper wires, fiber-optic, wireless).
TCP/IP is the most common network protocol. The operating systems support of
protocols also varies. Most operating systems support TCP/IP, including the Windows and UNIX
operating systems.
Networks are characterized based on the distances between their nodes. A local-area
network (LAN) connects computers within a room, a floor, or a building. A wide-area network
(WAN) usually links buildings, cities, or countries. A global company may have a WAN to
connect its offices worldwide. These networks may run one protocol or several protocols. A
metropolitan-area network (MAN) connects buildings within a city. Bluetooth and 802.11
devices use wireless technology to communicate over a distance of several feet, in essence
creating a small-area network such as might be found in a home.
The transportation media to carry networks are also varied. They include copper wires,
fiber strands, and wireless transmissions between satellites, microwave dishes, and radios. When
computing devices are connected to cellular phones, they create a network.
There are different classes of computer systems, whose functions are more limited and specific
and it deal with limited computation domains. The systems can be classified as Real-Time
Embedded Systems, Multimedia Systems and Handheld Systems.
The Operating Systems, in these embedded systems vary considerably. Some systems
have standard operating systems—such as UNIX—with special-purpose applications. Others
have special-purpose embedded operating system providing just the functionality desired.
Embedded systems always run real-time operating systems. A real-time system is used when
there is restricted time for an operation or for the flow of data. A real-time system functions
correctly only if it returns the correct result within its time constraints. Sensors bring data to the
computer. The computer must analyze the data and perform certain action.
Entire houses can be computerized, so that a computer —can control heating and lighting, alarm
systems, and even coffee makers. Web access can enable a home owner to tell the house to heat
up before she arrives home.
The amount of physical memory in a handheld depends upon the device, the operating system
and applications must manage memory efficiently. This includes returning all allocated memory
back to the memory manager when the memory is not being used. A second issue of concern to
developers of handheld devices is the speed of the processor used in the devices. Processors for
most handheld devices run at faster speed than the processor in a PC. Faster processors require
more power and so, a larger battery is required. Another issue is the usage of I/O devices.
Generally, the limitations in the functionality of PDAs are balanced by their convenience and portability.
Their use continues to expand as network connections become more available and other options, such as
digital cameras and MP3 players, expand their utility.
The current trend is toward providing more ways to access these computing
environments. Web technologies are stretching the boundaries of traditional computing.
Companies establish
portals, which provide web accessibility to their internal servers. Network computers are
essentially terminals that understand web-based computing. Handheld computers can
synchronize with PCs to allow very portable use of company information. Handheld PDAs can
also connect to wireless networks to use the company's web portal. The fast data connections are
allowing home computers to serve up web pages and to use networks. Some homes even have
firewalls to protect their networks.
In the latter half of the previous century, computing resources were scarce. Years before, systems
were either batch or interactive. Batch system processed jobs in bulk, with predetermined input
(from files or other sources of data). Interactive systems waited for input from users. To optimize
the use of the computing resources, multiple users shared time on these systems. Time-sharing
systems used a timer and scheduling algorithms to rapidly cycle processes through the CPU,
giving each user a share of the resources.
Today, traditional time-sharing systems are used everywhere. The same scheduling technique is
still in use on workstations and servers, but frequently the processes are all owned by the same
user (or a single user and the operating system). User processes, and system processes that
provide services to the user, are managed so that each frequently gets a slice of computer time.
Server systems can be broadly categorized as compute servers and file servers:
The compute-server system provides an interface to which a client can send a request to
perform an action (for example, read data); in response, the server executes the action and
sends back results to the client. A server running a database that responds to client
requests for data is an example of such a system.
The file-server system provides a file-system interface where clients can create, update,
read, and delete files. An example of such a system is a web server that delivers files to
In this model, clients and servers are not distinguished from one another; here, all nodes within
the system are considered peers, and each may act as either a client or a server, depending on
whether it is requesting or providing a service.
In a client-server system, the server is a bottleneck, because all the services must be
served by the server. But in a peer-to-peer system, services can be provided by several nodes
distributed throughout the network.
To participate in a peer-to-peer system, a node must first join the network of peers. Once a node
has joined the network, it can begin providing services to—and requesting services from—other
nodes in the network. Determining what services are available is accomplished in one of two
general ways:
When a node joins a network, it registers its service with a centralized lookup service on
the network. Any node desiring a specific service first contacts this centralized lookup
service to determine which node provides the service. The remainder of the
communication takes place between the client and the service provider.
A peer acting as a client must know, which node provides a desired service by
broadcasting a request for the service to all other nodes in the network. The node (or
nodes) providing that service responds to the peer making the request. To support this
approach, a discovery protocol must be provided that allows peers to discover services
provided by other peers in the network.
Web computing has increased the importance on networking. Devices that were not
previously networked now include wired or wireless access. Devices that were networked now
have faster network connectivity.
The implementation of web-based computing has given rise to new categories of devices, such as
load balancers, which distribute network connections among a pool of similar servers. Operating
systems like Windows 95, which acted as web clients, have evolved into Linux and Windows
XP, which can act as web servers as well as clients. Generally, the Web has increased the
complexity of devices, because their users require them to be web-enabled.
The design of an operating system is a major task. It is important that the goals of the new
system be well defined before the design of OS begins. These goals form the basis for choices
among various algorithms and strategies.
programs. OS provide services for the users of the system (Fig. 1.11),
including:
User Interfaces - Means by which users can issue commands to the system. Depending
on the operating system these may be a command-line interface (e.g. sh, csh, ksh, tcsh,
etc.), a Graphical User Interface (e.g. Windows, X-Windows, KDE, Gnome, etc.), or a
batch command system. In Command Line Interface (CLI)- commands are given to the
system. In Batch interface – commands and directives to control these commands are put
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 RAM, run the
program, and terminate the program, either normally or abnormally.
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).
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.
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.
Command Interpreters are used to give commands to the OS. There are multiple
command interpreters known as shells. In UNIX and Linux systems, there are several different
shells, like the Bourne shell, C shell, Bourne-Again shell, Korn shell, and others.
The main function of the command interpreter is to get and execute the user-specified
command. Many of the commands manipulate files: create, delete, list, print, copy, execute, and
so on.
1) The command interpreter itself contains the code to execute the command. For example, a
command to delete a file may cause the command interpreter to jump to a particular section of its
code that sets up the parameters and makes the appropriate system call (Fig. 1.12).
2) The code to implement the command is in a function in a separate file. The interpreter
searches for the file and loads it into the memory and executes it by passing the parameter. Thus,
by adding new functions new commands can be added easily to the interpreter without disturbing
it.
Another way of interfacing with the operating system is through a user-friendly graphical user
interface, or GUI. Here, rather than entering commands directly via a command-line interface,
users employ a mouse-based window and menu system. The user moves the mouse to position its
pointer on images, or icons on the screen (the desktop) that represent programs, files, directories,
and system functions. Depending on the mouse pointer's location, clicking a button on the mouse
can invoke a program, select a file or directory-known as a folder-or pull down a menu that
contains commands (Fig. 1.13).
Graphical user interfaces first appeared on the Xerox Alto computer in 1973.
Most modern systems allow individual users to select their desired interface, and to customize
its operation, as well as the ability to switch between different interfaces as needed.
System calls is a means to access the services of the operating system. Generally written in C
or C++, although some are written in assembly for optimal performance.
The below Fig. 1.14 illustrates the sequence of system calls required to copy a file content
from one file (input file) to another file (output file).
There are number of system calls used to finish this task. The first system call is to write a
message on the screen (monitor). Then to accept the input filename. Then another system calls to
write message on the screen, then to accept the output filename.
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) and create a
new one (another system call).
Now that both the file as 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 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 Fig. 1.17.
Each system call has a specific numbered system call. 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.
The relationship between an API, the system-call interface, and the operating system is shown in Fig 1.15.
which illustrates how the operating system handles a user application invoking the open () system call.
Three general methods used to pass parameters to OS are –
Fig. 1.15 The handling of a user application invoking the open Q system call.
The system calls can be categorized into six major categories as shown in Fig 1.17:
Process Control
File management
Device management
Information management
Communications
Protection
a) Process Control
Process control system calls include end, abort, load, execute, create process, terminate
process, get/set process attributes, wait for time or event, signal event, and allocate and
free memory.
Processes must be created, launched, monitored, paused, resumed, and eventually stopped.
When one process pauses or stops, then another must be launched or resumed
Process attributes like process priority, max. allowable execution time etc. are set and
retrieved by OS.
After creating the new process, the parent process may have to wait (wait time), or wait
for an event to occur (wait event). The process sends back a signal when the event has
occurred (signal event).
o In DOS, the command interpreter loaded first. Then loads the process and transfers
control to it. The interpreter does not resume until the process has completed, as shown
in Fig. 1.18.
o Because UNIX is a multi-tasking system, the command interpreter remains completely
resident when executing a process, as shown in Fig. 2.11 below.
The user can switch back to the command interpreter at any time, and can place
the running process in the background even if it was not originally launched as a
background process.
In order to do this, the command interpreter first executes a "fork" system call,
which creates a second process which is an exact duplicate (clone) of the original
command interpreter. The original process is known as the parent, and the cloned
process is known as the child, with its own unique process ID and parent ID.
The child process then executes an "exec" system call, which replaces its code
with that of the desired process.
The parent (command interpreter) normally waits for the child to complete before
issuing a new command prompt, but in some cases, it can also issue a new
prompt
right away, without waiting for the child process to complete. (The child is then
said to be running "in the background", or "as a background process".)
b) File Management
The file management functions of OS are –
File management system calls include create file, delete file, open, close, read, write,
reposition, get file attributes, and set file attributes.
After creating a file, the file is opened. Data is read or written to a file.
The file pointer may need to be repositioned to a point.
The file attributes like filename, file type, permissions, etc. are set and retrieved using
system calls.
These operations may also be supported for directories as well as ordinary files.
c) Device Management
Device management system calls include request device, release device, read, write,
reposition, get/set device attributes, and logically attach or detach devices.
When a process needs a resource, a request for resource is done. Then the control is
granted to the process. If requested resource is already attached to some other process, the
requesting process has to wait.
In multiprogramming systems, after a process uses the device, it has to be returned to OS,
so that another process can use the device.
Devices may be physical (e.g. disk drives), or virtual / abstract (e.g. files, partitions, and
RAM disks).
d) Information Maintenance
Information maintenance system calls include calls to get/set the time, date, system data,
and process, file, or device attributes.
These system calls care used to transfer the information between user and the OS.
Information like current time & date, no. of current users, version no. of OS, amount of
free memory, disk space etc. are passed from OS to the user.
e) Communication
Communication system calls create/delete communication connection, send/receive
messages, transfer status information, and attach/detach remote devices.
The message passing model must support calls to:
o Identify a remote process and/or host with which to communicate.
o Establish a connection between the two processes.
o Open and close the connection as needed. Transmit messages along the connection.
o Wait for incoming messages, in either a blocking or non-blocking state.
o Delete the connection when no longer needed.
The shared memory model must support calls to:
o Create and access memory that is shared amongst processes (and threads. )
o Free up shared memory and/or dynamically allocate it as needed.
there are system calls for each read and write process.
Shared memory is faster, and is generally the better approach where large amounts of data are
to be shared. This model is difficult to implement, and it consists of only few system calls.
f) Protection
Protection provides mechanisms for controlling which users / processes have access to
which system resources.
System calls allow the access mechanisms to be adjusted as needed, and for non-
privileged users to be granted elevated access permissions under carefully controlled
temporary circumstances.
File management - programs to create, delete, copy, rename, print, list, and generally
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 - e.g., text editors and other tools which can change file contents.
Any system to be designed must have its own goals and specifications. Similarly, the OS to be
built will have its own goals depending on the type of system in which it will be used, the type of
Requirements define properties which the finished system must have, and are a necessary step
in designing any large complex system. The requirements may be of two basic groups:
User requirements are featuring that users care about and understand like system should
be convenient to use, easy to learn, reliable, safe and fast.
System requirements are written for the developers, ie. People who design the OS. Their
requirements are like easy to design, implement and maintain, flexible, reliable, error free
and efficient.
Policies change overtime. In the worst case, each change in policy would require a change in
the underlying mechanism.
If properly separated and implemented, policy changes can be easily adjusted without re- writing
the code, just by adjusting parameters or possibly loading new data / configuration files.
1.19.3 Implementation
The advantages of using a higher-level language for implementing operating systems are:
The code can be written faster, more compact, easy to port to other systems and is easier to
understand and debug.
OS structure must be carefully designed. The task of OS is divided into small components and
then interfaced to work together.
UNIX OS (Fig. 1.20) consists of two separable parts: the kernel and the system programs. The
kernel is further separated into a series of interfaces and device drivers. The kernel provides the
file system, CPU scheduling, memory management, and other operating-system functions
through system calls.
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 (Fig. 1,21). Bottom layer (layer 0) is the
hardware and the topmost layer is the user interface. A typical layer, consists of data structure
and routines that can be invoked by higher-level layer.
The layers are selected so that each uses functions and services of only lower-level layers. So,
simplifies debugging and system verification. The layers are debugged one by one from the
lowest and if any layer doesn’t work, then error is due to that layer only, as the lower layers are
already debugged. Thus, the design and implementation are simplified.
A layer need not know how its lower-level layers are implemented. Thus, hides the operations
from higher layers.
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.
1.20.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.
Most microkernels provide basic process and memory management, and message passing between
other services (Fig. 1.22).
Benefit of microkernel - System expansion can also be easier, because it only involves adding
more system applications, not rebuilding a new kernel.
Mach was the first and most widely known microkernel, and now forms a major component of
Mac OSX.
Disadvantage of Microkernel is, it suffers from reduction in performance due to increases
system function overhead.
1.20.4 Modules
Modern OS development is object-oriented, with a relatively small core kernel and a set of
modules as shown in Fig. 1.23 which can be linked in dynamically.
Modules are similar to layers 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. E.g.:
Solaris, Linux and MacOS.
The Max OSX architecture relies on the Mach microkernel for basic system management
services, and the BSD kernel for additional services. Application services and dynamically
loadable modules ( kernel extensions ) provide the rest of the OS functionality. Resembles
layered system, but a module can call any other module.
Resembles microkernel, the primary module has only core functions and the knowledge of how
to load and communicate with other modules.
The fundamental idea behind a virtual machine is to abstract the hardware of a single computer
(the CPU, memory, disk drives, network interface cards, and so forth) into several different
execution environments, thereby creating the illusion that each separate execution environment is
running its own private computer (Fig. 1.24) .
Creates an illusion that a process has its own processor with its own memory. Host OS is the
main OS installed in system and the other OS installed in the system are called guest OS.
Fig. 1.24 System modes. (A) Nonvirtual machine (b) Virtual machine
Virtual machines first appeared as the VM Operating System for IBM mainframes in 1972.
1.21.2 Benefits
Able to share the same hardware and run several different execution environments (OS).
Host system is protected from the virtual machines and the virtual machines are protected
from one another. A virus in guest OS, will corrupt that OS but will not affect the other
guest systems and host systems.
Even though the virtual machines are separated from one another, software resources can
be shared among them. Two ways of sharing s/w resource for communication are:
The operating system runs on and controls the entire machine. Therefore, the current
system must be stopped and taken out of use while changes are made and tested. This
period is commonly called system development time. In virtual machines such problem is
eliminated. User programs are executed in one virtual machine and system development
is done in another environment.
Multiple OS can be running on the developer’s system concurrently. This helps in rapid
porting and testing of programmer’s code in different environments.
System consolidation – two or more systems are made to run in a single system.
1.21.3 Simulation –
Here the host system has one system architecture and the guest system is compiled in
different architecture. The compiled guest system programs can be run in an emulator that
translates each instructions of guest program into native instructions set of host system.
1.21.4 Para-Virtualization –
This presents the guest with a system that is similar but not identical to the guest’s preferred
system. The guest must be modified to run on the para-virtualized hardware.
1.21.5 Examples
a) VMware
VMware is a popular commercial application that abstracts Intel 80X86 hardware into isolated
virtual machines. The virtualization tool runs in the user-layer on top of the host OS. The virtual
machines running in this tool believe they are running on bare hardware, but the fact is that it is
running inside a user-level application (Fig. 1.25).
VMware runs as an application on a host operating system such as Windows or Linux and
allows this host system to concurrently run several different guest operating systems as
independent virtual machines.
In below scenario, Linux is running as the host operating system; FreeBSD, Windows
NT, and Windows XP are running as guest operating systems. The virtualization layer is the
heart of VMware, as it abstracts the physical hardware into isolated virtual machines running as
guest operating systems. Each virtual machine has its own virtual CPU, memory, disk drives,
network interfaces, and so forth.
Java was designed from the beginning to be platform independent, by running Java only
on a Java Virtual Machine, JVM, of which different implementations have been
developed for numerous different underlying HW platforms.
Java source code is compiled into Java byte code in .class files. Java byte code is binary
instructions that will run on the JVM.
JVM consists of class loader and Java Interpreter. Class loader loads compiled .class files
from both java program and java API for the execution of java interpreter. Then it checks
the .class file for validity.
OSes may be designed and built for a specific HW configuration at a specific site, but
more commonly they are designed with a number of variable parameters and
components, which are then conFig.d for a particular operating environment.
Systems sometimes need to be re-conFig.d after the initial installation, to add additional
resources, capabilities, or to tune performance, logging, or security.
At one extreme the OS source code can be edited, re-compiled, and linked into a new
kernel.
More commonly configuration tables determine which modules to link into the new
kernel, and what values to set for some key important parameters. This approach may
require the configuration of complicated make files, which can be done either
automatically or through interactive configuration programs; Then make is used to
actually generate the new kernel specified by the new parameters.
At the other extreme a system configuration may be entirely defined by table data; in
which case the "rebuilding" of the system merely requires editing data tables.
Once a system has been regenerated, it is usually required to reboot the system to activate
the new kernel. Because there are possibilities for errors, most systems provide some
mechanism for booting to older or alternate kernels.
The general approach when most computers boot up goes something like this:
When the system powers up, an interrupt is generated which loads a memory address into
the program counter, and the system begins executing instructions found at that address.
This address points to the "bootstrap" program located in ROM chips (or EPROM chips
) on the motherboard.
The ROM bootstrap program first runs hardware checks, determining what physical
resources are present and doing power-on self-tests (POST) of all HW for which this is
applicable. Some devices, such as controller cards may have their own on-board
diagnostics, which are called by the ROM bootstrap program.
The user generally has the option of pressing a special key during the POST process,
which will launch the ROM BIOS configuration utility if pressed. This utility allows the
user to specify and conFig.d. certain hardware parameters as where to look for an OS and
whether or not to restrict access to the utility with a password.
Assuming the utility has not been invoked, the bootstrap program then looks for a non-
volatile storage device containing an OS. Depending on configuration, it may look for a
floppy drive, CD ROM drive, or primary or secondary hard drives, in the order specified
by the HW configuration utility.
Assuming it goes to a hard drive, it will find the first sector on the hard drive and load up
the fdisk table, which contains information about how the physical hard drive is divided
up into logical partitions, where each partition starts and ends, and which partition is the
"active" partition used for booting the system.
There is also a very small amount of system code in the portion of the first disk block not
occupied by the fdisk table. This bootstrap code is the first step that is not built into the
hardware, i.e., the first part which might be in any way OS-specific. Generally, this code
knows just enough to access the hard drive, and to load and execute a (slightly) larger
boot program.
For a single-boot system, the boot program loaded off of the hard disk will then proceed
to locate the kernel on the hard drive, load the kernel into memory, and then transfer
control over to the kernel.
There may be some opportunity to specify a particular kernel to be loaded at this stage,
which may be useful if a new kernel has just been generated and doesn't work, or if the
system has multiple kernels available with different configurations for different purposes.
(Some systems may boot different configurations automatically, depending on what
hardware has been found in earlier steps. )
For dual-boot or multiple-boot systems, the boot program will give the user an
opportunity to specify a particular OS to load, with a default choice if the user does not
pick a particular OS within a given time frame. The boot program then finds the boot
loader for the chosen single-boot OS, and runs that program as described in the previous
bullet point.
Once the kernel is running, it may give the user the opportunity to enter into single-user
mode, also known as maintenance mode. This mode launches very few if any system
services, and does not enable any logins other than the primary log in on the console. This
mode is used primarily for system maintenance and diagnostics.
RV Institute of Technology &
Management®
III SEMESTER OPERATING SYSTEM (BCS303)