Operating System Summary
Operating System Summary
Definition
An operating system is 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
• File Management
• Security
• Control over system performance
• Job accounting
• Error detecting aids
• Coordination between other software and users
Memory Management
Memory management refers to management of Primary Memory or
Main Memory. Main memory is a large array of words or bytes
where each word or byte has its own address.
Processor Management
In multiprogramming environment, the OS decides which process
gets the processor when and for how much time. This function is
called process scheduling. An Operating System does the following
activities for processor management −
File Management
A file system is normally organized into directories for easy
navigation and usage. These directories may contain files and other
directions.
• Problem of reliability.
• Question of security and integrity of user programs and data.
• Problem of data communication.
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.
• Program execution
• I/O operations
• File System manipulation
• Communication
• Error Detection
• Resource Allocation
• Protection
Program execution
Operating systems handle many kinds of activities from user
programs to system programs like printer spooler, name servers,
file server, etc. Each of these activities is encapsulated as a process.
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
In case of multi-user or multi-tasking environment, resources such
as main memory, CPU cycles and files storage are to be allocated to
each user or job. Following are the major activities of an operating
system with respect to resource management −
Disadvantages
Multitasking
Multitasking is when 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. An OS does the following activities related to multitasking
−
Disadvantages
Interactivity
Interactivity refers to the ability of users to interact with a computer
system. An Operating system does the following activities related to
interactivity −
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.
Stack
1 The process Stack contains the temporary data such as method/function parameters, return
address and local variables.
Heap
2
This is dynamically allocated memory to a process during its run time.
Text
3 This includes the current activity represented by the value of Program Counter and the
contents of the processor's registers.
Data
4
This section contains the global and static variables.
Program
A program is a piece of code which may be a single line or millions
of lines. A computer program is usually written by a computer
programmer in a programming language. For example, here is a
simple program written in C programming language –
#include <stdio.h>
int main() {
printf("Hello, World! \n");
return 0;
}
Start
1
This is the initial state when a process is first started/created.
Ready
The process is waiting to be assigned to a processor. Ready processes are waiting to have
2 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.
Running
Once the process has been assigned to a processor by the OS scheduler, the process state is
3
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.
Terminated or Exit
5 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.
Process State
1
The current state of the process i.e., whether it is ready, running, waiting, or whatever.
Process privileges
2
This is required to allow/disallow access to system resources.
Process ID
3
Unique identification for each of the process in the operating system.
Pointer
4
A pointer to parent process.
Program Counter
5 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.
Accounting information
9
This includes the amount of CPU used for process execution, time limits, execution ID etc.
IO status information
10
This includes a list of I/O devices allocated to the process.
• 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.
Running
1
When a new process is created, it enters into the system as in the running state.
Not Running
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
2
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
Schedulers are special system software which handle 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.
Schedulers are of three types −
• Long-Term Scheduler
• Short-Term Scheduler
• Medium-Term Scheduler
It is a process swapping
1 It is a job scheduler It is a CPU scheduler
scheduler.
Speed is lesser than short Speed is fastest among Speed is in between both short
2
term scheduler other two and long term scheduler.
It is almost absent or
It is also minimal in time It is a part of Time sharing
4 minimal in time sharing
sharing system systems.
system
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
P0 0-0=0
P1 5-1=4
P2 8-2=6
P3 16 - 3 = 13
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
P0 0 5 1 0
P1 1 3 2 11
P2 2 8 1 14
P3 3 6 3 5
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
For example, CPU-bound jobs can be scheduled in one queue and all
I/O-bound jobs in another queue. The Process Scheduler then
alternately selects jobs from each queue and assigns them to the
CPU based on the algorithm assigned to the queue.
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.
Difference between Process and Thread
S.N. Process Thread
Process switching needs interaction with operating Thread switching does not need to
2
system. interact with operating system.
Multiple processes without using threads use more Multiple threaded processes use
5
resources. fewer resources.
In multiple processes each process operates One thread can read, write or
6
independently of the others. change another thread's data.
Advantages of Thread
• Threads minimize the context switching time.
• Use of threads provides concurrency within a process.
• Efficient communication.
• It is more economical to create and context switch threads.
• Threads allow utilization of multiprocessor architectures to a
greater scale and efficiency.
Types of Thread
Threads are implemented in following two ways −
• User Level Threads − User managed threads.
• Kernel Level Threads − Operating System managed threads
acting on kernel, an operating system core.
Advantages
Disadvantages
Advantages
Disadvantages
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
User-level thread is generic and can run on any Kernel-level thread is specific to the
3
operating system. operating system.
Symbolic addresses
1 The addresses used in a source code. The variable names, constants, and instruction labels are
the basic elements of the symbolic address space.
Relative addresses
2
At the time of compilation, a compiler converts symbolic addresses into relative addresses.
Physical addresses
3 The loader generates these addresses at the time when a program is loaded into main
memory.
At the time of loading, with static loading, the absolute program (and
data) is loaded into memory in order for execution to start.
If you are using dynamic loading, dynamic routines of the library are
stored on a disk in relocatable form and are loaded into memory
only when they are needed by the program.
Swapping
Swapping is a mechanism in which a process can be swapped
temporarily out of main memory (or move) to secondary storage
(disk) and make that memory available to other processes. At some
later time, the system swaps back the process from the secondary
storage to main memory.
Memory Allocation
Main memory usually has two partitions −
Single-partition allocation
In this type of allocation, relocation-register scheme is used to protect user processes from
1 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.
Multiple-partition allocation
In this type of allocation, main memory is divided into a number of fixed-sized partitions
2 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 −
External fragmentation
1 Total memory space is enough to satisfy a request or to reside a process in it, but it is not
contiguous, so it cannot be used.
Internal fragmentation
2 Memory block assigned to process is bigger. Some portion of memory is left unused, as it
cannot be used by another process.
Address Translation
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.
Segmentation
Segmentation is a memory management technique in which each
job is divided into several segments of different sizes, one for each
module that contains pieces that perform related functions. Each
segment is actually a different logical address space of the program.
Demand Paging
A demand paging system is quite similar to a paging system with
swapping where processes reside in secondary memory and pages
are loaded only on demand, not in advance. When a context switch
occurs, the operating system does not copy any of the old
program’s pages out to the disk or any of the new program’s pages
into the main memory Instead, it just begins executing the new
program after loading the first page and fetches that program’s
pages as they are referenced.
While executing a program, if the program references a page which
is not available in the main memory because it was swapped out a
little ago, the processor treats this invalid memory reference as
a page fault and transfers control from the program to the operating
system to demand the page back into the memory.
Advantages
When the page that was selected for replacement and was paged
out, is referenced again, it has to read in from disk, and this
requires for I/O completion. This process determines the quality of
the page replacement algorithm: the lesser the time waiting for
page-ins, the better is the algorithm.
Reference String
The string of memory references is called reference string.
Reference strings are generated artificially or by tracing a given
system and recording the address of each memory reference. The
latter choice produces a large number of data, where we note two
things.
• For a given page size, we need to consider only the page
number, not the entire address.
• If we have a reference to a page p, then any immediately
following references to page p will never cause a page fault.
Page p will be in memory after the first reference; the
immediately following references will not fault.
• For example, consider the following sequence of addresses −
123,215,600,1234,76,96
• If page size is 100, then the reference string is 1,2,6,12,0,0
Device Controllers
Device drivers are software modules that can be plugged into an OS
to handle a particular device. Operating System takes help from
device drivers to handle all I/O devices.
This uses CPU instructions that are specifically made for controlling
I/O devices. These instructions typically allow data to be sent to an
I/O device or read from an I/O device.
Memory-mapped I/O
Step Description
DMA controller transfers bytes to buffer, increases the memory address, decreases the
5
counter C until C becomes zero.
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.
Interrupts I/O
Device Drivers
Device drivers are software modules that can be plugged into an OS
to handle a particular device. Operating System takes help from
device drivers to handle all I/O devices. Device drivers encapsulate
device-dependent code and implement a standard interface in such
a way that code contains device-specific register reads/writes.
Device driver, is generally written by the device's manufacturer and
delivered along with the device on a CD-ROM.
Interrupt handlers
An interrupt handler, also known as an interrupt service routine or
ISR, is a piece of software or more specifically a callback function in
an operating system or more specifically in a device driver, whose
execution is triggered by the reception of an interrupt.
File Structure
A File Structure should be according to a required format that the
operating system can understand.
• A file has a certain defined structure according to its type.
• A text file is a sequence of characters organized into lines.
• A source file is a sequence of procedures and functions.
• An object file is a sequence of bytes organized into blocks that
are understandable by the machine.
• When operating system defines different file structures, it also
contains the code to support these file structure. Unix, MS-
DOS support minimum number of 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
Special files
• Sequential access
• Direct/Random access
• Indexed sequential access
Sequential access
Direct/Random access
• Contiguous Allocation
• Linked Allocation
• Indexed Allocation
Contiguous Allocation
Linked Allocation
Indexed Allocation
• Authentication
• One Time passwords
• Program Threats
• System Threats
• Computer Security Classifications
Authentication
Authentication refers to identifying each user of the system and
associating the executing programs with those users. It is the
responsibility of the Operating System to create a protection system
which ensures that a user who is running a particular program is
authentic. Operating Systems generally identifies/authenticates
users using following three ways −
Program Threats
Operating system's processes and kernel do the designated task as
instructed. If a user program made these process do malicious
tasks, then it is known as Program Threats. One of the common
example of program threat is a program installed in a computer
which can store and send user credentials via network to some
hacker. Following is the list of some well-known program threats.
System Threats
System threats refers to misuse of system services and network
connections to put user in trouble. System threats can be used to
launch program threats on a complete network called as program
attack. System threats creates such an environment that operating
system resources/ user files are misused. Following is the list of
some well-known system threats.
1 Type A
Highest Level. Uses formal design specifications and verification techniques. Grants a high
degree of assurance of process security.
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
2 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.
Type C
Provides protection and user accountability using audit capabilities. It is of two types.
• C1 − Incorporates controls so that users can protect their private information and
3
keep other users from accidentally reading / deleting their data. UNIX versions are
mostly Cl class.
• C2 − Adds an individual-level access control to the capabilities of a Cl level system.
Type D
4
Lowest level. Minimum protection. MS-DOS, Window 3.1 fall in this category.
Basic Features
Following are some of the important features of Linux Operating
System.
• Portable − Portability means software can works on different
types of hardware in same way. Linux kernel and application
programs supports their installation on any kind of hardware
platform.
• Open Source − Linux source code is freely available and it is
community based development project. Multiple teams work in
collaboration to enhance the capability of Linux operating
system and it is continuously evolving.
• Multi-User − Linux is a multiuser system means multiple users
can access system resources like memory/ ram/ application
programs at same time.
• Multiprogramming − Linux is a multiprogramming system
means multiple applications can run at same time.
• Hierarchical File System − Linux provides a standard file
structure in which system files/ user files are arranged.
• Shell − Linux provides a special interpreter program which can
be used to execute commands of the operating system. It can
be used to do various types of operations, call application
programs. etc.
• Security − Linux provides user security using authentication
features like password protection/ controlled access to specific
files/ encryption of data.
Architecture
The following illustration shows the architecture of a Linux system −
The architecture of a Linux System consists of the following layers −