Operating System IBPS
Operating System IBPS
Operating System IBPS
com
Operating System
Concepts
Contents:
1. Introduction
2. Types of OS
3. OS Properties
4. Intro. to Processes
5. CPU Scheduling
6. Scheduling Algorithms
7. Multithreading
8. Memory Management
9. Spooling
10. Virtual Memory
11. I/O Hardware
12. I/O Software
Engistan.com
Operating System
An operating system is a program that manages the computer hardware. It also provides a basis for
application programs and acts as an intermediary between the computer user and the computer
hardware.
Hence, an Operating System can be defined as a program that acts as an interface between the user
and the computer hardware and controls the execution of all kinds of programs.
Memory Management
Processor Management
Device Management
Storage Management
Application Interface
User Interface
Security
The main function of a batch processing system is to automatically keep executing the jobs
in a batch.
Engistan.com
It includes special functions for connecting computers and devices into a local-area network
(LAN) or Inter-network.
In real time operating system there is a little swapping of programs between primary and
secondary memory.
Batch processing: Batch processing is a technique in which Operating System collects one
programs and data together in a batch before processing starts. Operating system does the
following activities related to batch processing.
Engistan.com
II.
Multitasking: Multitasking refers to term where multiple jobs are executed by the CPU
simultaneously by switching between them. Switches occur so frequently that the users may
interact with each program while it is running.
III.
Multiprogramming: When two or more programs are residing in memory at the same time,
then sharing the processor is referred to the multiprogramming. Multiprogramming assumes
a single shared processor. Multiprogramming increases CPU utilization by organizing jobs so
that the CPU always has one to execute.
IV.
Interactivity: Interactivity refers that a User is capable to interact with computer system.
Operating system does the following activities related to interactivity.
OS provides user an interface to interact with system.
OS managers input devices to take inputs from the user. For example, keyboard.
OS manages output devices to show outputs to the user. For example, Monitor.
OS Response time needs to be short since the user submits and waits for the result.
Introduction to PROCESSES:
Process: A process is a program in execution. The execution of a process must progress in a
sequential fashion. Definition of process is following.
A process is defined as an entity which represents the basic unit of work to be implemented
in the system.
Engistan.com
Status: Verifies the status of the process execution. A process can run to completion
only when all requested resources have been allocated to the process. Two or more
processes could be executing the same program, each using their own data and
resources.
Program: A program by itself is not a process. It is a static entity made up of program statement
while process is a dynamic entity. Program contains the instructions to be executed by processor.
A program takes a space at single place in main memory and continues to stay there. A
program does not perform any action by itself.
Process States: As a process executes, it changes state. The state of a process is defined as the
current activity of the process.
Process can have one of the following five states at a time.
S.N. State & Description
1
Running: Process instructions are being executed (i.e. The process that is currently
being executed).
Waiting: The process is waiting for some event to occur (such as the completion of
an I/O operation).
Engistan.com
Process Scheduling: The process scheduling is the activity of the process manager that handles the
removal of the running process from the CPU and the selection of another process on the basis of a
particular strategy.
Process scheduling is an essential part of a Multiprogramming operating system. Such operating
systems allow more than one process to be loaded into the executable memory at a time and loaded
process shares the CPU using time multiplexing.
Scheduling Queues: Scheduling queues refers to queues of processes or devices. When the
process enters into the system, then this process is put into a job queue. This queue consists
of all processes in the system. The operating system also maintains other queues such as
device queue. Device queue is a queue for which multiple processes are waiting for a
particular I/O device. Each device has its own device queue.
This figure shows the queuing diagram of process scheduling.
Engistan.com
CPU Scheduling:
CPU Scheduling is the process by which an Operating System decides which programs get to use the
CPU. CPU scheduling is the basis of MULTIPROGRAMMED operating systems. By switching the CPU
among processes, the operating system can make the computer more productive.
CPU Schedulers: Schedulers are special system softwares which handles process scheduling in
various ways. Their main task is to select the jobs to be submitted into the system and to decide
which process to run.
0-0=0
P1
5-1=4
P2
8-2=6
P3
16 - 3 = 13
Engistan.com
3-0=3
P1
0-0=0
P2
16 - 2 = 14
P3
8-3=5
Engistan.com
0-0=0
P1
3-1=2
P2
8-2=6
P3
16 - 3 = 13
Engistan.com
(0-0) + (12-3) = 9
P1
(3-1) = 2
P2
6-2) + (15-9) = 10
P3
(9-3) + (18-12) = 12
Multi-Threading
Thread: A thread is a flow of execution through the process code, with its own program counter,
system registers and stack. A thread is also called a light weight process. Threads provide a way to
improve application performance through parallelism. Threads represent a software approach to
improving performance of operating system by reducing the overhead thread is equivalent to a
classical process.
Each thread belongs to exactly one process and no thread can exist outside a process. Each thread
represents a separate flow of control. Threads have been successfully used in implementing network
servers and web server. They also provide a suitable foundation for parallel execution of applications
on shared memory multiprocessors. Following figure shows the working of the single and
multithreaded processes.
Engistan.com
Process
Thread
1.
2.
3.
In multiple processing
environments each process
executes the same code but has its
own memory and file resources.
4.
5.
6.
10
Engistan.com
Advantages of Thread
Efficient communication.
Types of Thread
Threads are implemented in following two ways
Memory Management:
Memory management is the functionality of an operating system which handles or manages
primary memory. Memory management keeps track of each and every memory location either it is
allocated to some process or it is free. It checks how much memory is to be allocated to processes.
It decides which process will get memory at what time. It tracks whenever some memory gets freed
or unallocated and correspondingly it updates the status.
Memory management provides protection by using two registers, a base register and a limit
register. The base register holds the smallest legal physical memory address and the limit register
specifies the size of the range. For example, if the base register holds 300000 and the limit register
is 1209000, then the program can legally access all addresses from 300000 through 411999.
11
Engistan.com
Compile time: When it is known at compile time where the process will reside, compile
time binding is used to generate the absolute code.
Load time: When it is not known at compile time where the process will reside in memory,
then the compiler generates re-locatable code.
Execution time: If the process can be moved during its execution from one memory
segment to another, then binding must be delayed to be done at run time
Dynamic Loading
In dynamic loading, a routine of a program is not loaded until it is called by the program. All routines
are kept on disk in a re-locatable load format. The main program is loaded into memory and is
executed. Other routines methods or modules are loaded on request. Dynamic loading makes
better memory space utilization and unused routines are never loaded.
Dynamic Linking
Linking is the process of collecting and combining various modules of code and data into a
executable file that can be loaded into memory and executed. Operating system can link system
level libraries to a program. When it combines the libraries at load time, the linking is called static
linking and when this linking is done at the time of execution, it is called as dynamic linking.
In static linking, libraries linked at compile time, so program code size becomes bigger whereas in
dynamic linking libraries linked at execution time so program code size remains smaller.
Swapping
Swapping is a mechanism in which a process can be swapped temporarily out of main memory to a
backing store, and then brought back into memory for continued execution.
Backing store is a usually a hard disk drive or any other secondary storage which fast in access and
large enough to accommodate copies of all memory images for all users. It must be capable of
providing direct access to these memory images.
12
Engistan.com
Memory Allocation
Main memory usually has two partitions
Description
In this type of allocation, relocation-register scheme is
used to protect user processes from each other, and
from changing operating-system code and data.
Relocation register contains value of smallest physical
address whereas limit register contains range of logical
addresses. Each logical address must be less than the
limit register.
Single-partition allocation
13
Engistan.com
Fragmentation
As processes are loaded and removed from memory, the free memory space is broken into little
pieces. It happens after sometimes that processes cannot be allocated to memory blocks considering
their small size and memory blocks remains unused. This problem is known as Fragmentation.
Fragmentation is of two types
S.N. Fragmentation
Description
External fragmentation can be reduced by compaction or shuffle memory contents to place all free
memory together in one large block. To make compaction feasible, relocation should be dynamic.
Paging
External fragmentation is avoided by using paging technique. Paging is a technique in which physical
memory is broken into blocks of the same size called pages (size is power of 2, between 512 bytes
and 8192 bytes). When a process is to be executed, it's corresponding pages are loaded into any
available memory frames.
Logical address space of a process can be non-contiguous and a process is allocated physical memory
whenever the free memory frame is available. Operating system keeps track of all free frames.
Operating system needs n free frames to run a program of size n pages.
Address generated by CPU is divided into
Page number (p) -- page number is used as an index into a page table which contains base
address of each page in physical memory.
Page offset (d) -- page offset is combined with base address to define the physical memory
address.
14
Engistan.com
Segmentation
Segmentation is a technique to break memory into logical pieces where each piece represents a
group of related information. For example ,data segments or code segment for each process, data
segment for operating system and so on. Segmentation can be implemented using or without using
paging.
Unlike paging, segment are having varying sizes and thus eliminates internal fragmentation.
External fragmentation still exists but to lesser extent.
15
Engistan.com
Segment number (s) -- segment number is used as an index into a segment table which
contains base address of each segment in physical memory and a limit of segment.
Segment offset (o) -- segment offset is first checked against limit and then is combined with
base address to define the physical memory address.
Spooling: Spooling is an acronym for simultaneous peripheral operations on line. Spooling refers
to putting data of various I/O jobs in a buffer. This buffer is a special area in memory or hard disk
which is accessible to I/O devices. Operating system does the following activities related to
distributed environment.
OS handles I/O device data spooling as devices have different data access rates.
16
Engistan.com
OS maintains the spooling buffer which provides a waiting station where data can rest while
the slower device catches up.
Virtual Memory
Virtual memory is a technique that allows the execution of processes which are not completely
available in memory. The main visible advantage of this scheme is that programs can be larger than
physical memory. Virtual memory is the separation of user logical memory from physical memory.
This separation allows an extremely large virtual memory to be provided for programmers when
only a smaller physical memory is available. Following are the situations, when entire program is not
required to be loaded fully in main memory.
I/O Hardware
Computers operate on many kinds of devices. General types include storage devices (disks,
tapes),transmission devices (network cards, modems), and human-interface devices (screen,
Engistan.com
keyboard, mouse). Other devices are more specialized. A device communicates with a computer
system by sending signals over a cable or even through the air.
The device communicates with the machine via a connection point termed a port (for example, a
serial port). If one or more devices use a common set of wires, the connection is called a bus.In other
terms, a bus is a set of wires and a rigidly defined protocol that specifies a set of messages that can
be sent on the wires.
Daisy chain
When device A has a cable that plugs into device B, and device B has a cable that plugs into device C,
and device C plugs into a port on the computer, this arrangement is called a daisy chain. It usually
operates as a bus.
Controller
A controller is a collection of electronics that can operate a port, a bus, or a device. A serial-port
controller is an example of a simple device controller. This is a single chip in the computer that
controls the signals on the wires of a serial port.
The SCSI bus controller is often implemented as a separate circuit board (a host adapter) that plugs
into the computer. It contains a processor, microcode, and some private memory to enable it to
process the SCSI protocol messages. Some devices have their own built-in controllers.
I/O port
An I/O port typically consists of four registers, called the status , control, data-in, and data-out
registers.
S.N. Register & Description
Status Register
The status register contains bits that can be read by the host. These bits indicate
states such as whether the current command has completed, whether a byte is
available to be read from the data-in register, and whether there has been a device
error.
Control register
The control register can be written by the host to start a command or to change the
mode of a device. For instance, a certain bit in the control register of a serial port
chooses between full-duplex and half-duplex communication, another enables parity
checking, a third bit sets the word length to 7 or 8 bits, and other bits select one of the
speeds supported by the serial port.
18
Data-in register
The data-in register is read by the host to get input.
Engistan.com
4
Data-out register
The data out register is written by the host to send output.
Polling
Polling is a process by which a host waits for controller response. It is a looping process, reading the
status register over and over until the busy bit of status register becomes clear. The controller
uses/sets the busy bit when it is busy working on a command, and clears the busy bit when it is
ready to accept the next command. The host signals its wish via the command-ready bit in the
command register. The host sets the command-ready bit when a command is available for the
controller to execute.
I/O devices
I/O Devices can be categorized into following category.
S.N. Category & Description
Human readable
Human Readable devices are suitable for communicating with the computer user.
Examples are printers, video display terminals, keyboard etc.
Machine readable
Machine Readable devices are suitable for communicating with electronic equipment.
Examples are disk and tape drives, sensors, controllers and actuators.
Communication
Communication devices are suitable for communicating with remote devices.
Examples are digital line drivers and modems.
19
Engistan.com
Device Controllers
A computer system contains a many types of I/O devices and their respective controllers
network card
graphics adapter
disk controller
DVD-ROM controller
serial port
USB
sound card
20
Engistan.com
Non-maskable interrupt - Such kind of interrupts are reserved for events like unrecoverable
memory errors.
Maskable interrupt - Such interrupts can be switched off by the CPU before the execution of
critical instructions that must not be interrupted.
21