M1
M1
OPERATING SYSTEM
UNIT 1: INTRODUCTION
Operating system is an intermediary between the user and hardware.
Eg: Windows, Mac OSx, Linux, Android, Novell Network OS, Sun OS
When I say an operating system, it can be found in microwave, vacuum cleaner, Calculator etc but
each of these have their own feature and a way of operating with/without user interaction.
The goals of an operating system is
Hardware: Provides basic computing resources like CPU, Memory, I/O Devices
Operating System: controls and co-ordinates the hardware among the applications and
users
Application Programs: The user programs to do specific tasks like word, video games, photo
editor, web browsers etc
Users: People, machines and other computers
A person who uses the personal computer, monopolizes the resources of the single system.
The goal is to maximize the work he is performing, in this case the operating system must
be designed for ease of use for user with some importance given to the performance and no
importance for resource allocation.
A user who sits at a dummy terminal connected to a mainframe or minicomputer will be
sharing the resources with other users who using the same mainframe via another dummy
terminal. In this case the resource utilization should be properly maximized by the
operating system.
A user who works on a workstation connected to a networks of other workstations and
servers, these users have dedicated resources at their disposal but still they share some of
the networking and servers- file, compute and print servers. So operating system is
designed to compromise between individual usability and resource utilization.
Recently, many varieties of handheld devices have come to use which are standalone units
for individual users, some connected to network either wired or wireless. Because of power,
speed and interface limitations, they perform less operations. Here operating system is
designed for individual usability and performance per battery life.
Some of the embedded computer systems does not have user interaction like automobiles,
microwave oven etc. These operating systems are designed primarily to run without user
intervention.
System View:
Operating System
User programs
1
2
3
4
.
.
.
.
.
n
Fig 2: Main memory Usage
As shown in Fig 2, the operating system uses 1/4th of the main memory which is stored during
system start up. The user programs occupy the remaining 3/4th of the main memory for the
program executions. Normally the user program block is equally divided into ‘n’ number of blocks
such that ‘n’ number of user programs can be executed simultaneously.
Storage Structure:
The memory is divided into main memory and secondary memory. For a computer program to
execute the program must be in main memory. The main memory is the only large storage area
which a processor can access directly. Recently, main memory is implemented in a semiconductor
technology called dynamic random-access memory (DRAM), which forms an array of memory
words. Each word has a specific address.
Operating System
Interaction between the processor and main memory is achieved through a sequence of load and
store instructions to specific memory addresses.
The load instruction moves a word from main memory to internal register within a CPU, whereas
the store instruction moves the content of register to main memory. Apart from this, the CPU can
automatically load from main memory for execution.
A typical instruction-execution cycle is executed on a system with a von Neumann architecture:
Fetches the instruction from memory and stores that in instruction register.
The instruction is decoded and some of the operands may be fetched from memory and
stored in internal register of the CPU.
After the instructions on the operands has been executed, the result will be stored back in
the memory.
Ideally we want the data and instruction to be stored in main memory permanently. But this is not
possible as:
Main memory is usually too small to store all the needed programs and data permanently.
Main memory is volatile, it loses its contents when the power is turned off.
Thus most of the computer systems provide secondary storage as an extension of main memory.
Various secondary storage devices are electronic disk (HDD), magnetic disk, optical disk, magnetic
tapes, flash memory.
Most of the programs are stored on these disks until they are loaded onto the memory.Many
programs use these disks as both source and destination of the information for their processing.
Storage systems provide the basic functionality of storing the data and holding them until it is
retrieved at a later time. But the main differences among the various storage systems lies in speed,
cost, size and volatility.
According to the speed and cost, the higher levels of the hierarchy are expensive but faster in
execution, whereas the access time increases as we move down and also the devices in lower levels
are less expensive.
Operating System
Volatile storage loses the memory when the power is turned off.
Non-volatile storage does not lose the memory even when power is turned off.
In the hierarchy, electronic disks (HDD) can be either volatile or non-volatile.
o During normal operation, the data is stored in large DRAM array, which is volatile.
o Some electronic disk devices contain a hidden magnetic hard disk and a battery for
backup power.
o If the power is interrupted, the electronic disk controller copies the data from RAM
to the magnetic hard disk.
o When the power comes back the data is copied back to the RAM.
One CPU is used which executes both general purpose instruction set including instructions
from user processes.
Also consists of special purpose processors in the form of device specific processors such as
disk, keyboard, and graphics controllers or on mainframes in form of general purpose
processors such as I/O processors.
Special purpose processors run limited set of instructions and do not run user processes.
Operating systems sends the information about their next task and monitor its status. For
eg, disk controller microprocessor receives a sequence of requests from main CPU and
implements its own disk queue and scheduling algorithm.
Keyboard microprocessors used to convert keystrokes into codes to be sent to CPU.
Multiprocessor Systems:
Clustered system gathers together multiple CPU’s. However they are composed of 2 or more
individual systems joined together via network.
Operating System
Clustering provides High availability service; that the service will continue even when one
or more systems in a cluster fail.
A layer of cluster software runs on the cluster nodes. Each nodes can monitor one or more
nodes over LAN. If the monitored node fails then the monitoring node takes the ownership
and executes the applications that were running on the failed machine.
Clustering can be structured into Asymmetric clustering and Symmetric clustering
o In asymmetric clustering one node will be in hot standby mode while the other is
running the applications. Hot standby node monitors the active server only, if server
fails then hot standby node becomes active server.
o In symmetric clustering, 2 or more nodes are running applications and are
monitoring each other.
Cluster provides high performance computing environment which can provide significantly
greater computational power than single processor or SMP because they are capable of
running an application concurrently on all computers in a cluster.
Applications can use the concept of parallelization. Parallelization is a technique where
program is divided into separate components and are executed parallel on individual
computers in a cluster.
Operating System Structure:
One of the important aspect of operating systems is multiprogramming. A single program cannot
keep the CPU or I/O devices busy all the time. Multiprogramming increases CPU utilization by
organizing jobs so that CPU always has one to execute.
Operating system keeps several jobson disk in a job pool as main memory is too small to
accommodate all jobs. This pool consists of all processes waiting for allocation on main
memory.
One job is selected and executed called as job scheduling. Ifa job has to wait for some other
operations to finish its own work then the operating system switches to other jobs by
selecting from job pool.
Job scheduling is a process of bringing a job from the job pool to main memory.
A program loaded into memory for execution is called as process.
Processes is switched if has to wait for I/O operations for its work and I/O is busy in other
process work.
Time sharing is logical extension of multiprogramming which can be used in an interactive
environment where the jobs are being switched so frequently that the users can interact with each
program while it is running.
Time shared operating system uses CPU scheduling and multiprogramming to provide each
user with a small portion of time shared computer i.e each user will have at least 1 separate
program in memory
The user gives instruction from the keyboard and waits for immediate results on output
device. The response time should be short i.e less than 1 second.
Time shared operating system allows many users to share the system simultaneously as it
switches from one process to another at rapid speed.
Operating System
Each user is given a time share and Time shared operating system switches among them by
providing service without interruption creating an illusion to user that only he is using the
entire system.
CPU scheduling is a selection of jobs to be executed where several jobs are ready to run at
the same time.
Operating System Operations:
The operating system is interrupt driven. A trap is a software interrupt caused either by an error or
a specific request from the user program for an operating system service to be performed.
If there is an error in user program then that error must cause problem to only one program in
running but not all the other programs. For eg,if a process gets struck in an infinite loop, this loop
can prevent correct operations of many other processes.
To overcome these problems 2 techniques are used. They are Dual mode operation and Timer.
Dual Mode Operation:In order to ensure proper operation of the operating system, we must be able
to distinguish between the execution of operating system code and user defined code.
At least 2 modes are required: user mode and kernel mode. A bit called mode bit is added to
hardware of computer to indicate the current mode: kernel(0) or user(1).
A process uses resources like CPU, memory, files and I/O devices for execution.
Logical and physical memory is also being used along with data transfer from I/O devices.
Once the process execution is completed, the operating system takes back the resources
provided earlier to process.
If a single threaded process is executing, then only 1 program counter is used where next
instruction is stored for execution.
If multiple threaded processes are used then multiple program counters are used for same
purpose.
The function of operating system in process management is
o Scheduling processes and threads for execution
o Creating and deleting user and system processes.
o Suspending and resuming processes.
o Providing mechanisms for process synchronization
o Providing mechanisms for process communication
Memory Management:
CPU reads the instruction from the main memory by using instruction fetch cycle
CPU reads and writes the data to/from memory by data fetch cycle.
When a process is loaded into memory it must done along with absolute address.
When the process is executed, the required data and instructions are fetched from that
absolute address.
To improve the speed and CPU utilization general purpose computers stores several
programs inside the memory for long time.
The function of operating system in memory management is
o Keep track of which parts of memory is being accessed and by whom
o Deciding which process and data to move into and out of memory
o Allocating and deallocating memory space when needed.
Storage Management:
File management system:
A file is collection of information defined by the user. It may be numeric, alphabetic,
alphanumeric or binary. Data files may be in free form (texts) or may be formatted rigidly.
Directories are created to store these files for easier access.
Files may be stored on magnetic disk, optical disk and magnetic tapes.
Each of these media has its own characteristics and physical organization. Each medium is
controlled by device such as disk drive or tape drive.
The properties include access speed, capacity, data transfer rate and access method
(sequential or random)
Operating System
Security is defense mechanism against internal and external attacks like denial-of-service,
worms, viruses, identity theftand theft of service.
Systems generally first distinguish among users, to determine who can do what
o User identities (user IDs, security IDs) include name and associated number, one
per user
o User ID then associated with all files, processes of that user to determine access
control
o Group identifier (group ID) allows set of users to be defined and controls managed,
then also associated with each process, file
o Privilege escalation allows user to change to effective ID with more rights
Distributed Systems:
Computer Server System: Interface to which client can send a request to perform an action,
the server responds by executing the action and sends the result back.
File server System: File system interface where the client can create, read, update, delete
files.
When a node joins, it must register its service with centralized lookup service on the
network. Any node desiring the service first it will check centralized look up.
A discovery protocol is provided to that allows peers to discover services provided by other
peers in the network.
User Interface: Almost all the operating systems provide user interface. A command line
interface uses text commands and executes them. A batch interface is one where the
commands and the directives for those commands are stored in a files and those files are
executed. Most of the operating systems uses Graphical User Interface where a command is
given with the help of mouse buttons by clicking on icons.
Program Execution: The system must be able to load the program into the memory and run
them. The program must be able to terminate itself either normally or abnormally.
I/O Operations: During the execution of programs, the I/O may be required which may be a
file or I/O device. For efficiency and performance the control of these I/O will not be given
to users, instead the operating system must provide a means for I/O.
File System manipulation: The programs may need to read, write files and directories. They
also need to create or delete a file or other operations can be performed like permissions
management on file ownership.
Communications: There may occur circumstances where one process will communicate
with other process residing either in same computer or in different computer. This is done
using either shared memory or through message passing over the network.
Error Detection: Operating system must constantly be aware of errors that may occur in
CPU, memory hardware, I/O devices and in the user program. For each type of error
operating system must be able to take appropriate actions to ensure correct and consistent
computing.
Another set of operations provides services to system which have multiple users. The efficiency can
be gained by sharing the computer resources among the users.
Resource Allocation: When there are multiple users or multiple programs running at same
time, resources must be allocated to each one of them. For efficient use of CPU, CPU
scheduling is done. To allocate I/O devices, special routines are run for printers, modems,
USB storage devices etc.
Accounting: Usage statistics of a user can be monitored and can be used for reconfiguring
the system to improve computing services.
Protection and Security: Protection involves all access to system resources are controlled.
Security from outsiders is also provided against attacks on system by also checking for
authentication of users.
User Operating system Interface:
Major interface between user and Operating system are of 2 types, namely command
interpreter and GUI
One of the benefit of using API’s over direct use of system call is that programming using
API concerns program portability. Application programmer can expect his program to
compile and run on any system which supports that API.
Actual system calls can be more detailed and difficult to work with than the API
available to any application programmer.
Fig 14: System call sequence to copy from one file to another file
The Fig 14 shows system call sequence to copy from one file to another file.
The run time support system provides a system call interface that serves as the link to system
calls made available by the operating system.
Operating System
Process Control
File Manipulation
Device Manipulation
Information Maintenance
Communication
Process Control:
end, abort
load, execute Save the memory or run parallel program
create process, terminate process
get process attributes, set process attributes control the attributes of job(priority, exec
time)
Operating System
File manipulation:
The design of an operating system must be started by defining goals and specifications. At
the highest level, the design of the system will be affected by hardware and the type of
system used like batch interface, single user, multi user, time shared, distributed, real time
or general purpose.
The requirements can be divided into user goals and system goals.
The user wants the system to be convenient to use, easy to learn and to use, reliable, safe
and fast.
The specifications required by the people who design, create, maintain and operate the
system will want the system to be easy to design, implement and maintain the system. And
it should be flexible, reliable, error free and efficient.
Implementation:
Layered approach must be appropriately defined into various layers since the higher layers
gets the service from low level layers, careful planning is necessary.
Layered implementations are less efficient than other types. For eg, a user program
executes I/O operation, it executes a system call that traps I/O layer which inturn calls
memory management layer which inturn calls CPU scheduling which inturn calls hardware.
In every level the parameters are modified and data may be passed and so on. Each layer
adds overhead to system call.
Microkernels:
This method structures the operating system by removing non-essential components from the
kernel and implementing them in system and user level programs. The result is smaller kernel.
Operating System
Microkernels provides minimal process and memory management in addition to communication
facility.
Communication is provided by message passing.
Advantage:
The operating system can be extended easily as the new programs can be added in the user
space and no modification is required in kernel for that purpose.
The operating system is easier to port to some other hardware.
The microkernels provide more security and reliability as error in 1 program in user space
does not affect the kernel in any way
Disadvantage:
Microkernels suffer from performance decrease due to increased system function overhead.
Modules:
Currently the design of an operating system involves using object oriented programming
techniques to create a modular kernel. Here the kernel has set of components and links in
additional services during run time. These dynamically loaded modules can be found in Unix
operating systems.
Host system is protected from the virtual machines. If a virus attacks happens in any of the
virtual machines, it does not affects the host operating system.
There is no direct sharing of resources, 2 approaches have been used: To share a file system
volume to share files. Or to define a network of virtual machines, each of which can send
information over the virtual communication network.
Virtual machines can be used for research and development. Operating system runs and
controls the entire machine. The current system in use is to be stopped and taken out for a
while changes are being made or tested. This period is commonly called as system
development time. System Programmers use virtual machines to eliminate this problem.
Multiple operating systems can be run on virtual machines by the developers which helps
them in rapid porting and testing of programs in varying environments.
System Consolidation is done in data center where 2 or more separate systems are running
in 1 virtual system. This results in resource optimization.
Emulators can also be used in case an old system is replaced by new system and the
programs running in old system have to be implemented in new system.
Virtual machine implementation:
Usually machines have 2 modes: user mode and kernel mode. The virtual machines also has these
modes: virtual user mode and virtual kernel mode which is executed in physical user mode. Those
transfer that cause from user mode to kernel mode must also cause the transfer from virtual user
mode to virtual kernel mode.
When a system call is made in virtual user mode by a program running in virtual machine, it will
cause the transfer to virtual machine monitor in real machine. When the virtual machine monitor
gains the control, it can change the values in registers and program counter for the virtual machine
to simulate the effect of system call.
The more the hardware support available within a system, the more feature rich, stable and well
performing virtual machines can be.
Example Virtual machines:
VMWare:
VMWare is a virtualization software which will run the user mode of host operating system.
Operating System
The compiler produces an architecture neutral bytecode output (.class file) that will run on
any JVM.
Operating System
The class loader loads the compiled .class file from both java program and java API for
execution by java interpreter.
After the class is loaded, the verifier checks the .class file is valid java bytecode and does not
overflow or underflow and also it checks whether it performs pointer arithmetic which
leads to erroneous results.
JVM also automatically manages memory by performing garbage collection.