Operating System Notes1
Operating System Notes1
Definition, Design Goals, Evolution, Structure & functions of operating System, process management,
memory management, concurrent processes, file & secondary Storage management, Unix & shell
programming, windows programming.
Operating System
Definition
Computer System:- roughly divided into 4 components- the hardware, the operating system, the application
program & the user.
The hardware (the CPU, memory & I/O devices) provides the basic Computing
resources for the system.
The application program defines the way in which these resources are used to
solve user's computing problems.
The OS coordinates hardware use among the various application programs for
the various users & also controls the hardware.
In other words: - we can also view a computer system as consisting of
hardware, software and data.
Operating System (OS): - An Operating system acts as an interface between user & hardware.
An OS is a program that manages the computer hardware. It also provides a basis of application program & acts as
an intermediary between the computer user and the computer hardware.
The Operating System is one program or system software running at all times on the computer - usually called the
Kernel. Along with the Kennel, there are 2 other types of programs:
1. System Program (software), which are associated with the OS but are not part of the Kernel.
2. Application Program (software): - which include all programs not associated with the operation of the system.
Operating system works as an extended machine: - The Job of the operating system is to create good abstractions
& then implement and manage the abstract objects thus created.
Operating System works as a Resource manager.
Design Goals of OS
Operating System is designed to accomplish some tasks & it varies as per the requirements.
Some OS are designed to be convenient, others to be efficient & others some combination of the both.
In user view: - the goal is to maximize the work that the user is performing. In this case OS is designed for ease of
use & high performance, but resource utilization is quite less.
The operating system should be convenient, easy to use, reliable, safe and fast according to the users.
In other cases multiple users access the mainframe for shared resources & exchange information. In such cases
the OS is designed to maximize resource utilization to assure that all available CPU time, memory & I/O are used
efficiently.
In still other cases, user sit at workstations connected to networks of other workstations & servers & share.
Resources such as file compute and print servers. Therefore their OS is designed to compromise between
individual usability & resource utilization.
Some Operating Systems are designed for individual usability as the computer is personal.
Some OS have little or no user view. For example embedded Computers in home devices & automobiles. These
operating System are designed primarily to run without user intervention.
In System view: - Operating System designed to be efficient in resource allocation. Resource allocation is
especially important where many users access the same mainframe or minicomputer.
The operating system should be easy to design, implement and maintain. These are specifications required by
those who create, maintain and operate the operating system.
A Computer system has many resources that may be required to solve a problem: CPU time, memory space,
files storage space, I/O devices etc.
Operating System acts as a controller to control the various I/O devices and user program.
Evolution
Computer-System Architecture
Single-Processor Systems:- Most systems use a single processor. The variety of single-
processor systems may be surprising, however, since these systems range from PDAS through
mainframes.
On a single-processor system, there is one main CPU capable of executing a general-purpose
instruction set, including instructions from user processes and also there are some special-
purpose processors as well.
Special purpose processor may come in the form of device-specific processors, such as disk,
keyboard, and graphics controllers.
All of these special-purpose processors run a limited instruction set and do not run user Single processor system
processes. Sometimes they are managed by the operating system,
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. Even if it has such special-purpose processors, a
system with only one core is still a single-processor system.
Trap
p & interrupts are event that disrupt the normal sequence of instructions executed by the CPU.
Trap:- Trap is an abnormal condition detected by the CPU that usually is indicative of an error.
erro
Example:- dividing by zero,, trying to access a memory location
cation that does not exist or for
fo which the
program does not have access, execuecuting instruction with an undefined
ned opcode, or trying to access
nonexistent I/o devices.
Trap is an exception & also called software interrupt.
interrupt
Interrupt vector is a memory space location of an interrupt handler where the CPU Knows the address of
the interrupt service routine in advance.
Interrupt service routine is a software interrupt handler
OS operation:- An operating system that has nothing to do will sleep or wait until a request for service
arrives (an interrupt). Interrupts can be generated by hardware or software.
software
Modern operating systems are interrupt driven.
For each type of interrupt,
nterrupt, separate segments of code
code in the operating system determine what
w action
should be taken.
An Interrupt Service Routine is provided that is responsible for dealing with the interrupt.
A properly designed operating system must ensure that an incorrect (or malicious) program can c not cause
other programs to execute incorrectly.
Dual-Mode operation:-
In order to ensure the proper
per execution of the operating system,
system, we must be able to distinguish
disting between
the execution of operating system Code & user defined code.
For this we need 2 separate modes of operation.
operation User mode and Kernel mode (also called supervisor
mode, system mode, privileged mode)
A bit called mode
de bit is added to the hardware of Computer to indicate the current mode: Kernel (0 bit) or
User (1 bit).
When the computer
puter system is executing, on behalf
be of a user application, the system is in user mode (0).
However when a user application requests a service from Operating System (via via a System Call) it must
transition from user to kernel mode to fulfil the request.
At system boot time the hardware re starts in Kernel mode. The OS is then loaded & starts user applications in
user mode, whenever a trap orr interrupt occurs; the hardware switches from user mode to Kernel mode.
Thus whenever the OS 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.
We accomplish this protection by designating some of the machinema instructions that harm as privileged
instruction. The hardware allows privileged instruction 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 & traps it to the OS.
OS
Timer:- A timer is a special CPU register. Each time it executes a user process in a CPU, the OS first places a
number N in the timer.
After each clock tick, the hardware automatically decrements the timer.
If the value reaches zero, the hardware immediately generates an interrupt.
This assures that the user process will allow the OS to resume execution in the CPU after no more
than N clock ticks.
The user process cannot disable or change the value in the timer. Such operations are privileged
instructions.
System Calls:- It provide the means for a user program to ask the Operating system to perform tasks
reserved for the OS on the behalf of user program.
It is the method used by a process to request action by the OS.
When a system call is executed, it is treated by the hardware as Software interrupt.
System calls provide an interface to the services made available by an operating system
When a system call is executed, the control passes through the interrupt vector to system call service
routine in OS & the mode bit set to the Kernel mode (0).
1. User interface: - Almost all operating system have a user interface. This interface can take several forms. A
a) Command line interface (CLI) which uses text commands & a method for entering them.
b) Batch interface: - In which commands & directives to Control those Commands are entered into
files and those files are executed.
c) Graphics user interface: - The Graphics user interface is a window system with a pointing device to
direct I/O choose from menus and make selections and a keyboard to enter text.
2. Communication:- There are many circumstances in which one process needs to exchange information with
another process. These processes can be on same system or on different system connected by a network.
Communication may be implemented via shared memory or through message passing.
3. Error detection: - Operating System needs to be constantly aware of possible errors. Errors may occur in
the CPU, memory and hardware (such as a memory error or a power failure), 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, or a too-great
use of CPU time).
Some function or services exist not for helping the user but rather for ensuring the efficient operation of
the system itself.
4. Resource management:- when there are multiple users or multiple jobs running at a same time, resources
must be allocated to each of them. There also be routine to may allocate printers, modems, USB storage
drives & other peripheral devices. There are some resources which are managed by Operating system:
a. Process Management:- The System must be able to load a process into memory & to run that
process.
The OS has to create and delete processes, Schedule processes (and threads) on CPUs, suspend and
resume processes, provide mechanisms for process synchronization, and provide mechanisms for
process communication.
b. Memory Management:- The OS has to keep track of which parts of memory are currently being used,
and which processes are using them;
allocate and deallocate memory space as needed; and decide which processes (or parts of processes)
and data to copy into or out of memory.
c. Mass Storage Management:- Regarding mass storage, the OS has to mount and unmount devices,
OS manages free space, allocates storage, schedules disk accesses, performs partitioning, and
provides protection.
d. Input/Output management:- A running program may require I/O, which may involve a file or an I/O
device. For efficiency & protection, user usually cannot control I/O devices directly, therefore OS
control I/O.
e. File - System management:- Programs needs to read and write files & directories.
direc Files also need to
create and delete by name,e, searching, listing the information of file
le all needs the OS management.
Some files & directories need permissions to allow or deny access to files or o directories based on file
ownership. Map files onto mass storage, and back up files on stable (non-volatile)
(non volatile) storage media.
5. Accounting:- we want to keep track of which user use how much and what kinds of computer resources.
This record keeping may be used for accounting or simply for accumulating usage statistics.
6. Protection & Security:- The owners of information stored in a multiuser or networked computer system
may wantnt to Central use of that information. when several processes run
run concurrently
concurrent it should not be
possible for one process to interfere with others or with the OS itself. Protection
ection involves ensuring that all
access to system resources is controlled.
controlled. Security of the system from outsider is also important.
Till now we have seen what Operating System looks like on the outside (Programmer's interface). Now we
will see the internal structure of the Operating System.
Operating System structure re can be divided into 5 parts:
parts
1. Simple or Monolithic structure:- In the Monolithic approach the entire OS runs as a single program in
Kernel mode.
The OS is written as a collection off procedures, linked
l together into a single large executable file (binary
program).
Advantages:- each procedure in the system is free to call any other one which makes the system efficient.
Disadvantages:- However having thousand of procedure that can call each other without restriction restricti may
also lead to a system that is unwieldy & difficult to understand.
If any service fails in the monolithic kernel, it leads to the failure of the entire system.
Such freedom leaves Monolithic system vulnerable to errant (or malicious) programs, causing entire
system crushes when user programs fail.
To add any new service, the entire operating system needs to be modified by the user.
To construct the actual object program of monolithic operating system one first compiles all the individual
procedure (or thee file containing the procedure)
procedure & then binds those all together into a single executable file
using the system linker.
There is no hidden information; every procedure is visible to every other procedure.
There are no modules & packages,
ackages, in which much of information is hidden away inside modules & only the
officially designated entry points, can
an be called from outside the module.
In this model, for each system call there is one service procedure that takes care of it & executes it. The
utility procedure does things that are needed by several service procedures, such as fetching the data from
user program.
The core Operating System that is loaded when the computer is booted. Many OS support loadable
extensions such as I/O, device drivers
rivers & file
fil systems.
These components are loaded on demand. In UNIX they are called shared Libraries & In windows they
Called DLL (Dynamic link libraries.)
Example:- MS DOS. It was written to provide more
functionality in less space so it was not divided
into modules carefully.
MS DOS was also limited by the hardware of its
era. Because the Intel 8088 for which it was
written provides no dual mode & no hardware
har
protection, the designer of MS DOS had no choice
but to leave the base hardware accessible.
Traditional UNIX is also example of monolithic
OS.
2. Layered Approach:-
To overcome the drawback of Monolithic & to improve the hardware protection the system must be
modular. So the next structure developed was layered one.
In layered approach the OS is organized as a hierarchy of layers, each one constructed upon the one below
it.
First System constructed in this way was the "THE" System. "by E W Dijkstra (1968)
The "THE" System was a simple batch system for a Dutch Computer, the Electrologica x8, which had 32K of
27 bit words.
The System has 6 layers.
i. Layer 0:- It dealt with allocation of the processor, switching between processes when interrupts
occurred or timers expired. Layer0 is a hardware layer.
ii. Layer 1:- It did the memory management and allocated space.
For processes in main memory & on a 512K word drum used for holding parts of processes (Pages) for
which there was no room in main memory.
Above layer1 process did not have to worry about whether they were in memory or in drum.
iii. Layer 2:- It handled Communication between each process and the Operator (user) Console.
iv. Layer 3:- It took care of managing the I/O devices & buffering the information streams to and from
them.
v. Layer 4:- Layer4 was where the user programs were found. Layer4 did not have to worry about
process, memory, Console or I/O management.
vi. Layer 5:- The system operator process was located in this layer.
Layers Function
Layer5 Users
Layer4 User programs
Layer3 I/O management
Layer2 Operator-process
communication
Layer1 Memory management
Layer0 Hardware
A layer does not need to know how these operations are implemented. It needs to know only what these
operations do.
Hence each layer hides the existence of certain data structures, operations and hardware from higher level
layers.
3. Mirrokernels:- C. Mellon University developed an OS called "MACH" that modularized the Kernel using
microkernel approach.
This method structures the OS by removing all non essential components from the Kernel & implementing
them as system and user level programs.
The result is a smaller and Separate Kernel.
Microkernel provides minimal process & memory management, in addition to a Communication facility.
The main function of the microkernel is to provide a communication facility between the client program
and various services that are also running in user space. Communication is provided by message passing.
Example:- If the client program wishes to access file, it must interact with the file server. The client
program & service never interact directly. Rather, they communicate indirectly by exchanging messages
with the microkernals.
One benefit of the microkernel approach is ease of extending the OS. All new services are added to user
space of consequently do not require modification of the Kernel. when the Kernel does have to be
modified the changes tends to be fewer, because microkernel is smaller Kernel. The resulting OS is easier
to port from one hardware design to another.
The Microkernel also provides more security & reliability since most services are running as user rather
than Kernel - processes. If a service fails, the rest of the OS remains unchanged.
The drawback of Microkernels is that it can suffer from performance decreases due to increased system
function overhead.
4. Modular Kernel:- It is considered as a best approach for an OS. It involves designing of a modular Kernel.
The Kernel has only set of core components and other services are added as dynamically loadable modules
to the Kernel either during run time or boot time.
Example1- Solaris OS structure is organized around a Core Kernel with seven types of loadable Kernel
modules:
a. Scheduling classes
b. File Systems
c. Loadable System Calls
d. executable file format
e. Streams module
f. device & bus driver
g. Miscellaneous
Example2:- Device & bus drivers for specific hardware can be added to the kernel & support for different
file systems can be added as loadable modules. The overall result resembles a layered system in that each
Kernel section has defined protected interfaces; but it is more flexible than a layered System in that any
module can call any other module.
Furthermore, the approach is like the microkernel approach in that the 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.
5. Virtual machines:- The logical conclusion of layered
structure in the concept of a virtual machine.
The fundamental hardware behind a virtual machine is
to abstract the hardware of a single computer (the ( CPU,
memory, disk drives, network, interface Cards & so
forth) into several
everal different execution environments,
thereby creating
reating the illusion that each separate
execution environment is running its own private
computer.
By using CPU scheduling
cheduling and virtual-memory
virtual
techniques, an OS host can create ate the illusion that a
process hass its own processor with its own (virtual)
memory.
1. Mainframe OS:- The OS for mainframes heavily are oriented toward processing many jobs at once, most of
which need prodigious amounts of I/O.
They typically offer
fer 3 kinds of services:
a) Batch System
b) Transaction processing
c) Time sharing.
a. Batch system is one that processes routine jobs without any interactive user present. Ex: - claims
processing in an insurance Company or sales reporting for a chain stores
sto is typically done in batch
mode.
b. Transaction processing systems handle large numbers of small requests
Example:- check processing at a bank oro airline reservation.
Each unit of work is small, but the system must handled hundreds or thousands per second.
c. Timesharing System allows multiple remote users to run jobs on Computer at once, such as querying a
big database.
2. Server OS: - They run on servers, which are very large personal computers, workstations or even
mainframes.
They serve multiple users at once over a network & allow the user to share hardware & Software
resources.
Servers can provide print service, file service or web service.
Typical server operating systems are Solaris, FreeBSD,
BSD, Linux & windows server 2000 etc.
etc
3. Multiprocessor OS:- An increasingly Common way to get major-league Computing power is to connect
multiple CPUs into a single system. Depending on precisely, How they are connected & what is shared.
These systems are called parallel computers, multiprocessor Computers, and multicomputer, with special
features for Communication Connectivity & Consistency.
4. Personal Computer OS:- Modern PC OS support multiprogramming and ten dozen of programs started up
at boot time.
Their job is to provide good support to single user used for word processing, internet access, games,
spreadsheet
Example: Linux, FreeBSD, Windows versions, Apple OSX etc
6. Embedded OS: - Embedded System runs on the computers that control devices that are not generally
thought of as computers and which do not accept user installed software.
Examples are Microwave ovens, TV sets, Cars, DVD recorders, traditional phones & MP3 players.
The main property which distinguishes embedded systems from handhelds is the certainty that no
untrusted software will ever run on it.
We cannot download new app to our microwave oven.
All the software is in ROM.
Systems such as Embedded Linux, QNX & Vxworks are popular in this domain.
7. Sensor - Node operating Systems:- Network of tiny sensor nodes are being deployed for numerous
purposes.
These nodes are tiny computers that communicate with each other and with a base station using wireless
communication.
Sensor network are used to protect the perimeters of buildings, guard national borders, detect fires in
forests, measure temperature & precipitation for weather forecasting, glean information about enemy
movements on battlefields etc.
The sensors are small battery-powered Computers with built-in radios. They have limited power & must
work for long periods of time unattended outdoors frequently in environmentally harsh Conditions.
Each Sensor node is real computer with a CPU, RAM, ROM & one or more environmental sensors.
It runs a small, but real OS, usually one that is event driven, responding to external events or making
measurement periodically based on an internal clock.
10. Multiprogramming OS:- Multiprogramming OS may run many programs on a single processor computer.
If one program must wait for an I/O transfer in a multiprogramming OS, the other programs are ready to
use the CPU.
As a result various jobs may Share CPU time. However the execution of their jobs is not defined to be at the
same time period.
The primary goal of multiprogramming is to manage the entire system's resources.
The Key Components of a multiprogramming system are the file system, command processor, transient
area & I/O Control system.
Multiprogramming OS are designed to store different programs based on sub segmenting parts of the
transient area. The resource management routines are linked with the OS Core functions.
12. Batch OS:- This type of OS does not interact with Computer directly. There is an operator which takes
similar jobs having the same requirement & groups them into batches.
Easy to manage large work repeatedly in batch systems.
Disadvantage is that the computer operators should be well known with batch system.
It is hard to debug & sometimes Costly. The other jobs will have to wait for an unknown time if any job
fails.
Example:- Payroll System, Bank Statements system, Attendance System etc.
13. Distributed OS:- Various autonomous interconnected Computers Communicate with each other using a
shared Communication network.
Independent unit (System) posses their own memory unit & CPU.
These are referred to as loosely coupled Systems or distributed systems.
Remote access is enabled within the devices Connected in that network.
Advantages:- Failure of one will not affect the other network Communication, as all systems are
independent from each other.
• Since Resources are being shared computation is highly fast & durable.
• Electronic mail increases the data exchange speed.
Disadvantages: Failure of main network will stop the entire communication.
• These types of systems are not readily available as they are very expensive. Not only that the
underlying software is highly complex & not understood well. yet.
Example: Locus.
14. Network OS:- These Systems run on a server & provide the capability to manage data, users, groups,
security, applications & other networking functions.
Over a small private network one more important aspect of Network OS is that all the users are well aware
of the underlying configuration of all other user within the network, their individual connections, etc &
that's why these computers are popularly known as tightly coupled systems..
Advantages: - Highly stable centralized servers.
• Security Concerns are handled through servers.
• New technologies & hardware up-gradation are easily integrated into the system.
• Server access is possible remotely from different locations & types of systems.
Disadvantages: Servers are costly.
• User has to depend on a central location for most operations.
• Maintenance & updates are required regularly.
• Example:- windows server 2003, windows server 2008, UNIX, LINUX, Mac OSX, BSD etc.