Operating System
Operating System
Definition
Memory Management
Processor Management
Device Management
File Management
Security
Control over system performance
Job accounting
Error detecting aids
Coordination between other software and users
Memory Management
Processor Management
Device Management
File Management
A file system is normally organized into directories for easy navigation and
usage. These directories may contain files and other directions.
Operating systems are there from the very first computer generation and
they keep evolving with time. In this chapter, we will discuss some of the
important types of operating systems which are most commonly used.
The users of a batch operating system do not interact with the computer
directly. Each user prepares his job on an off-line device like punch cards
and submits it to the computer operator. To speed up processing, jobs with
similar needs are batched together and run as a group. The programmers
leave their programs with the operator and the operator then sorts the
programs with similar requirements into batches.
The problems with Batch Systems are as follows −
Problem of reliability.
Question of security and integrity of user programs and data.
Problem of data communication.
With resource sharing facility, a user at one site may be able to use
the resources available at another.
Speedup the exchange of data with one another via electronic mail.
If one site fails in a distributed system, the remaining sites can
potentially continue operating.
Better service to the customers.
Reduction of the load on the host computer.
Reduction of delays in data processing.
A Network Operating System runs on a server and provides the server the
capability to manage data, users, groups, security, applications, and other
networking functions. The primary purpose of the network operating
system is to allow shared file and printer access among multiple computers
in a network, typically a local area network (LAN), a private network or to
other networks.
Examples of network operating systems include Microsoft Windows Server
2003, Microsoft Windows Server 2008, UNIX, Linux, Mac OS X, Novell
NetWare, and BSD.
The advantages of network operating systems are as follows −
Real-time systems are used when there are rigid time requirements on the
operation of a processor or the flow of data and real-time systems can be
used as a control device in a dedicated application. A real-time operating
system must have well-defined, fixed time constraints, otherwise the
system will fail. For example, Scientific experiments, medical imaging
systems, industrial control systems, weapon systems, robots, air traffic
control systems, etc.
There are two types of real-time operating systems.
Program execution
I/O operations
File System manipulation
Communication
Error Detection
Resource Allocation
Protection
Program execution
I/O Operation
I/O operation means read or write operation with any file or any
specific I/O device.
Operating system provides the access to the required I/O device when
required.
Communication
Error handling
Errors can occur anytime and anywhere. An error may occur in CPU, in I/O
devices or in the memory hardware. Following are the major activities of an
operating system with respect to error handling −
Resource Management
Protection
Batch processing
Advantages
Batch processing takes much of the work of the operator to the
computer.
Disadvantages
Multitasking
Multiprogramming
Sharing the processor, when two or more programs reside in memory at the
same time, is referred as multiprogramming. Multiprogramming assumes
a single shared processor. Multiprogramming increases CPU utilization by
organizing jobs so that the CPU always has one to execute.
The following figure shows the memory layout for a multiprogramming
system.
The operating system picks and begins to execute one of the jobs in
the memory.
Multiprogramming operating systems monitor the state of all active
programs and system resources using memory management
programs to ensures that the CPU is never idle, unless there are no
jobs to process.
Advantages
Disadvantages
Interactivity
Distributed Environment
Spooling
Advantages
Process
To put it in simple terms, we write our computer programs in a text file and
when we execute this program, it becomes a process which performs all the
tasks mentioned in the program.
When a program is loaded into the memory and it becomes a process, it can
be divided into four sections ─ stack, heap, text and data. The following
image shows a simplified layout of a process inside main memory −
1 Stack
The process Stack contains the temporary data such as method/function
parameters, return address and local variables.
2 Heap
This is dynamically allocated memory to a process during its run time.
3 Text
This includes the current activity represented by the value of Program
Counter and the contents of the processor's registers.
4 Data
This section contains the global and static variables.
Program
#include <stdio.h>
int main() {
printf("Hello, World! \n");
return 0;
}
A computer program is a collection of instructions that performs a specific
task when executed by a computer. When we compare a program with a
process, we can conclude that a process is a dynamic instance of a
computer program.
A part of a computer program that performs a well-defined task is known as
an algorithm. A collection of computer programs, libraries and related data
are referred to as a software.
1 Start
This is the initial state when a process is first started/created.
2 Ready
The process is waiting to be assigned to a processor. Ready processes are
waiting to have the processor allocated to them by the operating system so
that they can run. Process may come into this state after Start state or
while running it by but interrupted by the scheduler to assign CPU to
some other process.
3 Running
Once the process has been assigned to a processor by the OS scheduler,
the process state is set to running and the processor executes its
instructions.
4 Waiting
Process moves into the waiting state if it needs to wait for a resource, such
as waiting for user input, or waiting for a file to become available.
5 Terminated or Exit
Once the process finishes its execution, or it is terminated by the operating
system, it is moved to the terminated state where it waits to be removed
from main memory.
1 Process State
The current state of the process i.e., whether it is ready, running, waiting,
or whatever.
2 Process privileges
This is required to allow/disallow access to system resources.
3 Process ID
Unique identification for each of the process in the operating system.
4 Pointer
A pointer to parent process.
5 Program Counter
Program Counter is a pointer to the address of the next instruction to be
executed for this process.
6 CPU registers
Various CPU registers where process need to be stored for execution for
running state.
9 Accounting information
This includes the amount of CPU used for process execution, time limits,
execution ID etc.
10 IO status information
The PCB is maintained for a process throughout its lifetime, and is deleted
once the process terminates.
Definition
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
systems. Such operating systems allow more than one process to be loaded
into the executable memory at a time and the loaded process shares the
CPU using time multiplexing.
the state of a process is changed, its PCB is unlinked from its current
queue and moved to its new state queue.
The Operating System maintains the following important process
scheduling queues −
Job queue − This queue keeps all the processes in the system.
Ready queue − This queue keeps a set of all processes residing in
main memory, ready and waiting to execute. A new process is always
put in this queue.
Device queues − The processes which are blocked due to
unavailability of an I/O device constitute this queue.
The OS can use different policies to manage each queue (FIFO, Round
Robin, Priority, etc.). The OS scheduler determines how to move processes
between the ready and run queues which can only have one entry per
processor core on the system; in the above diagram, it has been merged
with the CPU.
1 Running
When a new process is created, it enters into the system as in the running
state.
2 Not Running
Notes Prepared by,
A.Bathsheba Parimala, Dept. of BCA,
St. John’s College, Palayamkotti
Operating System
Processes that are not running are kept in queue, waiting for their turn to
execute. Each entry in the queue is a pointer to a particular process.
Queue is implemented by using linked list. Use of dispatcher is as follows.
When a process is interrupted, that process is transferred in the waiting
queue. If the process has completed or aborted, the process is discarded.
In either case, the dispatcher then selects a process from the queue to
execute.
Schedulers
Long-Term Scheduler
Short-Term Scheduler
Medium-Term Scheduler
Context Switch
A context switch is the mechanism to store and restore the state or context
of a CPU in Process Control block so that a process execution can be
resumed from the same point at a later time. Using this technique, a
context switcher enables multiple processes to share a single CPU. Context
switching is an essential part of a multitasking operating system features.
When the scheduler switches the CPU from executing one process to
execute another, the state from the current running process is stored into
the process control block. After this, the state for the process to run next is
loaded from its own PCB and used to set the PC, registers, etc. At that
point, the second process can start executing.
Program Counter
Scheduling information
Base and limit register value
Currently used register
Changed State
I/O State information
Accounting information
A Process Scheduler schedules different processes to be assigned to the
CPU based on particular scheduling algorithms. There are six popular
process scheduling algorithms which we are going to discuss in this
chapter −
P0 0-0=0
P1 5-1=4
P2 8-2=6
P3 16 - 3 = 13
The processer should know in advance how much time process will
take.
Given: Table of processes, and their Arrival time, Execution time
P0 0 5 0
P1 1 3 5
P2 2 8 14
P3 3 6 8
P0 0-0=0
P1 5-1=4
P2 14 - 2 = 12
P3 8-3=5
Processes with same priority are executed on first come first served
basis.
Priority can be decided based on memory requirements, time
requirements or any other resource requirement.
Given: Table of processes, and their Arrival time, Execution time, and
priority. Here we are considering 1 is the lowest priority.
P0 0 5 1 0
P1 1 3 2 11
P2 2 8 1 14
P3 3 6 3 5
P0 0-0=0
P1 11 - 1 = 10
P2 14 - 2 = 12
P3 5-3=2
P0 (0 - 0) + (12 - 3) = 9
P1 (3 - 1) = 2
P3 (9 - 3) + (17 - 12) = 11
What is Thread?
A thread is a flow of execution through the process code, with its own
program counter that keeps track of which instruction to execute next,
system registers which hold its current working variables, and a stack
which contains the execution history.
A thread shares with its peer threads few information like code segment,
data segment and open files. When one thread alters a code segment
memory item, all other threads see that.
A thread is also called a lightweight 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. The following figure shows
the working of a single-threaded and a multithreaded process.
system.
4 If one process is blocked, then no other process can execute While one
until the first process is unblocked. thread is
blocked
and
waiting, a
second
thread in
the same
task can
run.
Advantages of Thread
Types of Thread
In this case, the thread management kernel is not aware of the existence of
threads. The thread library contains code for creating and destroying
threads, for passing message and data between threads, for scheduling
thread execution and for saving and restoring thread contexts. The
application starts with a single thread.
Advantages
Disadvantages
Advantages
Disadvantages
Kernel threads are generally slower to create and manage than the
user threads.
Transfer of control from one thread to another within the same
process requires a mode switch to the Kernel.
Multithreading Models
Some operating system provide a combined user level thread and Kernel
level thread facility. Solaris is a good example of this combined approach.
In a combined system, multiple threads within the same application can
run in parallel on multiple processors and a blocking system call need not
block the entire process. Multithreading models are three types
When thread makes a blocking system call, the entire process will be
blocked. Only one thread can access the Kernel at a time, so multiple
threads are unable to run in parallel on multiprocessors.
If the user-level thread libraries are implemented in the operating system in
such a way that the system does not support them, then the Kernel threads
use the many-to-one relationship modes.
The process address space is the set of logical addresses that a process
references in its code. For example, when 32-bit addressing is in use,
addresses can range from 0 to 0x7fffffff; that is, 2^31 possible numbers, for
a total theoretical size of 2 gigabytes.
The operating system takes care of mapping the logical addresses to
physical addresses at the time of memory allocation to the program. There
are three types of addresses used in a program before and after memory is
allocated −
1 Symbolic addresses
The addresses used in a source code. The variable names, constants, and
instruction labels are the basic elements of the symbolic address space.
2 Relative addresses
At the time of compilation, a compiler converts symbolic addresses into
relative addresses.
3 Physical addresses
The loader generates these addresses at the time when a program is loaded
into main memory.
Virtual and physical addresses are the same in compile-time and load-time
address-binding schemes. Virtual and physical addresses differ in
execution-time address-binding scheme.
The set of all logical addresses generated by a program is referred to as
a logical address space. The set of all physical addresses corresponding to
these logical addresses is referred to as a physical address space.
As explained above, when static linking is used, the linker combines all
other modules needed by a program into a single executable program to
avoid any runtime dependency.
When dynamic linking is used, it is not required to link the actual module
or library with the program, rather a reference to the dynamic module is
provided at the time of compilation and linking. Dynamic Link Libraries
(DLL) in Windows and Shared Objects in Unix are good examples of
dynamic libraries.
Swapping
memory available to other processes. At some later time, the system swaps
back the process from the secondary storage to main memory.
Though performance is usually affected by swapping process but it helps in
running multiple and big processes in parallel and that's the
reason Swapping is also known as a technique for memory compaction.
The total time taken by swapping process includes the time it takes to move
the entire process to a secondary disk and then to copy the process back to
memory, as well as the time the process takes to regain main memory.
Let us assume that the user process is of size 2048KB and on a standard
hard disk where swapping will take place has a data transfer rate around 1
MB per second. The actual transfer of the 1000K process to or from
memory will take
2048KB / 1024KB per second
Notes Prepared by,
A.Bathsheba Parimala, Dept. of BCA,
St. John’s College, Palayamkotti
Operating System
= 2 seconds
= 2000 milliseconds
Now considering in and out time, it will take complete 4000 milliseconds
plus other overhead where the process competes to regain main memory.
Memory Allocation
1 Single-partition allocation
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.
2 Multiple-partition allocation
In this type of allocation, main memory is divided into a number of fixed-
sized partitions where each partition should contain only one process.
When a partition is free, a process is selected from the input queue and is
loaded into the free partition. When the process terminates, the partition
becomes available for another process.
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 −
1 External fragmentation
2 Internal fragmentation
Memory block assigned to process is bigger. Some portion of memory is left
unused, as it cannot be used by another process.
Paging
between 512 bytes and 8192 bytes). The size of the process is measured in
the number of pages.
Similarly, main memory is divided into small fixed-sized blocks of (physical)
memory called frames and the size of a frame is kept the same as that of a
page to have optimum utilization of the main memory and to avoid external
fragmentation.
Address Translation
Page address is called logical address and represented by page
number and the offset.
Logical Address = Page number + page offset
Frame address is called physical address and represented by a frame
number and the offset.
Physical Address = Frame number + page offset
A data structure called page map table is used to keep track of the relation
between a page of a process to a frame in physical memory.
When the system allocates a frame to any page, it translates this logical
address into a physical address and create entry into the page table to be
used throughout execution of the program.
When a process is to be executed, its corresponding pages are loaded into
any available memory frames. Suppose you have a program of 8Kb but your
memory can accommodate only 5Kb at a given point in time, then the
paging concept will come into picture. When a computer runs out of RAM,
the operating system (OS) will move idle or unwanted pages of memory to
secondary memory to free up RAM for other processes and brings them
back when needed by the program.
This process continues during the whole execution of the program where
the OS keeps removing idle pages from the main memory and write them
onto the secondary memory and bring them back when required by the
program.
Segmentation
Demand Paging
Advantages
Following are the advantages of Demand Paging −
Disadvantages
Number of tables and the amount of processor overhead for handling
page interrupts are greater than in the case of the simple paged
management techniques.
Reference String
Oldest page in main memory is the one which will be selected for
replacement.
Easy to implement, keep a list, replace pages from the tail and add
new pages at the head.
Page which has not been used for the longest time in main memory is
the one which will be selected for replacement.
The page with the smallest count is the one which will be selected for
replacement.
This algorithm suffers from the situation in which a page is used
heavily during the initial phase of a process, but then is never used
again.
This algorithm is based on the argument that the page with the
smallest count was probably just brought in and has yet to be used.
One of the important jobs of an Operating System is to manage various I/O
devices including mouse, keyboards, touch pad, disk drives, display
adapters, USB devices, Bit-mapped screen, LED, Analog-to-digital
converter, On/off switch, network connections, audio I/O, printers etc.
Device Controllers
The CPU must have a way to pass information to and from an I/O device.
There are three approaches available to communicate with the CPU and
Device.
Memory-mapped I/O
When using memory-mapped I/O, the same address space is shared by
memory and I/O devices. The device is connected directly to certain main
memory locations so that I/O device can transfer block of data to/from
memory without going through CPU.
Slow devices like keyboards will generate an interrupt to the main CPU
after each byte is transferred. If a fast device such as a disk generated an
interrupt for each byte, the operating system would spend most of its time
handling these interrupts. So a typical computer uses direct memory
access (DMA) hardware to reduce this overhead.
Direct Memory Access (DMA) means CPU grants I/O module authority to
read from or write to memory without involvement. DMA module itself
controls exchange of data between main memory and the I/O device. CPU
is only involved at the beginning and end of the transfer and interrupted
only after entire block has been transferred.
Direct Memory Access needs a special hardware called DMA controller
(DMAC) that manages the data transfers and arbitrates access to the
system bus. The controllers are programmed with source and destination
pointers (where to read/write the data), counters to track the number of
transferred bytes, and settings, which includes I/O and memory types,
interrupts and states for the CPU cycles.
Ste Description
p
A computer must have a way of detecting the arrival of any type of input.
There are two ways that this can happen, known
as polling and interrupts. Both of these techniques allow the processor to
deal with events that can happen at any time and that are not related to
the process it is currently running.
Polling I/O
Polling is the simplest way for an I/O device to communicate with the
processor. The process of periodically checking status of the device to see if
it is time for the next I/O operation, is called polling. The I/O device simply
puts the information in a Status register, and the processor must come and
get the information.
Most of the time, devices will not require attention and when one does it
will have to wait until it is next interrogated by the polling program. This is
an inefficient method and much of the processors time is wasted on
unnecessary polls.
Compare this method to a teacher continually asking every student in a
class, one after another, if they need help. Obviously the more efficient
method would be for a student to inform the teacher whenever they require
assistance.
Interrupts I/O
An alternative scheme for dealing with I/O is the interrupt-driven method.
An interrupt is a signal to the microprocessor from a device that requires
attention.
Notes Prepared by,
A.Bathsheba Parimala, Dept. of BCA,
St. John’s College, Palayamkotti
Operating System
A device controller puts an interrupt signal on the bus when it needs CPU’s
attention when CPU receives an interrupt, It saves its current state and
invokes the appropriate interrupt handler using the interrupt vector
(addresses of OS routines to handle various events). When the interrupting
device has been dealt with, the CPU continues with its original task as if it
had never been interrupted.
I/O software is often organized in the following layers −
User Level Libraries − This provides simple interface to the user
program to perform input and output. For example, stdio is a library
provided by C and C++ programming languages.
Kernel Level Modules − This provides device driver to interact with
the device controller and device independent I/O modules used by
the device drivers.
Hardware − This layer includes actual hardware and hardware
controller which interact with the device drivers and makes hardware
alive.
A key concept in the design of I/O software is that it should be device
independent where it should be possible to write programs that can access
any I/O device without having to specify the device in advance. For
example, a program that reads a file as input should be able to read a file
on a floppy disk, on a hard disk, or on a CD-ROM, without having to modify
the program for each different device.
Device Drivers
Interrupt handlers
These are the libraries which provide richer and simplified interface to
access the functionality of the kernel or ultimately interactive with the
device drivers. Most of the user-level I/O software consists of library
procedures with some exception like spooling system which is a way of
dealing with dedicated I/O devices in a multiprogramming system.
I/O Libraries (e.g., stdio) are in user-space to provide an interface to the OS
resident device-independent I/O SW. For example putchar(), getchar(),
printf() and scanf() are example of user level I/O library stdio available in C
programming.
File
File Structure
File Type
File type refers to the ability of the operating system to distinguish different
types of file such as text files source files and binary files etc. Many
operating systems support many types of files. Operating system like MS-
DOS and UNIX have the following types of files −
Ordinary files
Directory files
These files contain list of file names and other information related to
these files.
Special files
File access mechanism refers to the manner in which the records of a file
may be accessed. There are several ways to access files −
Sequential access
Direct/Random access
Indexed sequential access
Sequential access
A sequential access is that in which the records are accessed in some
sequence, i.e., the information in the file is processed in order, one record
after the other. This access method is the most primitive one. Example:
Compilers usually access files in this fashion.
Direct/Random access
Random access file organization provides, accessing the records
directly.
Each record has its own address on the file with by the help of which
it can be directly accessed for reading or writing.
The records need not be in any sequence within the file and they need
not be in adjacent locations on the storage medium.
Space Allocation
Contiguous Allocation
Linked Allocation
Indexed Allocation
Contiguous Allocation
Linked Allocation
Indexed Allocation
Authentication
One Time passwords
Program Threats
System Threats
Computer Security Classifications
Authentication
Program Threats
System Threats
1 Type A
Highest Level. Uses formal design specifications and verification
techniques. Grants a high degree of assurance of process security.
2 Type B
Provides mandatory protection system. Have all the properties of a class
C2 system. Attaches a sensitivity label to each object. It is of three types.
B1 − Maintains the security label of each object in the system. Label
is used for making decisions to access control.
B2 − Extends the sensitivity labels to each system resource, such as
storage objects, supports covert channels and auditing of events.
B3 − Allows creating lists or user groups for access-control to grant
access or revoke access to a given named object.
3 Type C
4 Type D
Lowest level. Minimum protection. MS-DOS, Window 3.1 fall in this
category.
Basic Features
Architecture
1. What are the differences between Batch processing system and Real
Time Processing System?
2. What are the differences between Real Time System and Timesharing
System?
3. What are the differences etween multiprocessing and
multiprogramming?
6. Find out which algorithm among FCFS, SJF And Round Robin with
quantum 10, would give the minimum average time for a given
workload.
7. Explain pseudo parallelism? Describe the process model that makes
parallelism easier to deal with.