Os Notes
Os Notes
Polytechnic, Hisar
E-Contents
SEM: 3rd
RATIONALE
The course provides the students with an understanding of human computer interface
existing in computer system and the basic concepts of operating system and its working. The
students will also get hands-on experience and good working knowledge to work in
windows and Linux environments. The aim is to gain proficiency in using various operating
systems after undergoing this course. While imparting instructions, the teachers are expected
to lay more emphasis on concepts and principles of operating systems, its features and
practical utility.
LEARNING OUTCOMES
DETAILED CONTENTS
Process concept, Process State, Process Control Block, Scheduling Queues, Scheduler, Job
Scheduler, Process Scheduler, Context Switch, Operations on Processes, Interprocess
Communication, Shared Memory Systems, Message-Passing Systems, CPU Scheduler,
Scheduling Criteria, Scheduling Algorithms, Preemptive and Non Preemptive, First come
first serve (FCFS), Shortest Job first(SJF), Round Robin (RR), Multiprocessor scheduling,
Process Synchronization.
3. Deadlocks (Principles and Brief Concept) (04 periods)
Deadlock, Conditions for Dead lock, Methods for handling deadlocks, Dead Prevention,
Deadlock Avoidance, Deadlock detection, Recovery from deadlock.
Definition – Logical and Physical address Space, Swapping, Memory allocation, Contiguous
Memory allocation, Fixed and variable partition, Internal and External fragmentation and
Compaction, Paging – Principle of operation, Page allocation, Hardware support for paging,
Protection and sharing, Disadvantages of paging, Segmentation, Virtual Memory.
Dedicated Devices, Shared Devices, I/O Devices, Storage Devices, Buffering, Spooling.
Types of File System; Simple file system, Basic file system, Logical file system, Physical
file system, Various Methods of Allocating Disk Space
History of Linux and Unix, Linux Overview, Structure of Linux, Linux releases, Open
Linux, Linux System Requirements, Linux Commands and Filters: mkdir, cd,rmdir,pwd, ls,
who, whoami, date, cat,chmod, cp, mv, rm,pg,more, pr, tail, head, cut, paste, nl, grep, wc,
sort, kill, write, talk,mseg,wall, merge,mail, news Shell: concepts of command options,
input, output,redirection,pipes, redirecting and piping with standard errors, Shell scripts,vi
editing commands
RECOMMENDED BOOKS
http://swayam.gov.in
Unit 1
It works as an interface between the user and computer to perform all the tasks like memory
management, file management, input & output handling, security, process management, Job
accounting, error detecting, system performance controlling, peripheral devices controlling
like printers & disk drives. The popular operating systems mainly include Windows, Linux,
AIX, VMS, z/OS, etc.
Memory Management
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 −
Keeps tracks of processor and status of process. The program responsible for this
task is known as traffic controller.
Allocates the processor (CPU) to a process.
De-allocates processor when a process is no longer required.
Device Management
An Operating System manages device communication via their respective drivers. It does
the following activities for device management −
Keeps tracks of all devices. Program responsible for this task is known as the I/O
controller.
Decides which process gets the device when and for how much time.
Allocates the device in the efficient way.
De-allocates devices.
File Management
A file system is normally organized into directories for easy navigation and usage. These
directories may contain files and other directions.
An Operating System does the following activities for file management −
Keeps track of information, location, uses, status etc. The collective facilities are
often known as file system.
Decides who gets the resources.
Allocates the resources.
De-allocates the resources.
Following are some of the important activities that an Operating System performs −
Security − By means of password and similar other techniques, it prevents
unauthorized access to programs and data.
Control over system performance − Recording delays between request for a
service and response from the system.
Job accounting − Keeping track of time and resources used by various jobs and
users.
Error detecting aids − Production of dumps, traces, error messages, and other
debugging and error detecting aids.
Coordination between other softwares and users − Coordination and assignment
of compilers, interpreters, assemblers and other software to the various users of the
computer systems.
User Interface
User Interface: A user interface (UI) refers to the part of an operating system, program, or
device that allows a user to enter and receive information. A Character user interface
(CUI), displays text, and its commands are usually typed on a command line using a
keyboard. With a graphical user interface (GUI), the functions are carried out by clicking
or moving buttons, icons and menus by means of a pointing device.
Modern graphical user interfaces have evolved from text-based UIs. Some operating
systems can still be used with a text-based user interface. In this case, the commands are
entered as text.
In most operating systems, the primary user interface is graphical, i.e. instead of typing the
commands you manipulate various graphical objects (such as icons) with a pointing device.
Types of Operating System: some of the important types of operating systems which are
most commonly used are as:
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.
Distributed systems use multiple central processors to serve multiple real-time applications
and multiple users. Data processing jobs are distributed among the processors accordingly.
The processors communicate with one another through various communication lines (such
as high-speed buses or telephone lines). These are referred as loosely coupled systems or
distributed systems. Processors in a distributed system may vary in size and function. These
processors are referred as sites, nodes, computers, and so on.
The advantages of distributed systems are as follows −
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.
Network operating System
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 −
A real-time system is defined as a data processing system in which the time interval
required to process and respond to inputs is so small that it controls the environment. The
time taken by the system to respond to an input and display of required updated information
is termed as the response time. So in this method, the response time is very less as
compared to online processing.
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.
An Operating System provides services to both the users and to the programs.
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.
A process includes the complete execution context (code to execute, data to manipulate,
registers, OS resources in use). Following are the major activities of an operating system
with respect to program management −
I/O Operation
An I/O subsystem comprises of I/O devices and their corresponding driver software.
Drivers hide the peculiarities of specific hardware devices from the users.
An Operating System manages the communication between user and device drivers.
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.
A file represents a collection of related information. Computers can store files on the disk
(secondary storage), for long-term storage purpose. Examples of storage media include
magnetic tape, magnetic disk and optical disk drives like CD, DVD. Each of these media
has its own properties like speed, capacity, data transfer rate and data access methods.
A file system is normally organized into directories for easy navigation and usage. These
directories may contain files and other directions. Following are the major activities of an
operating system with respect to file management −
Communication
In case of distributed systems which are a collection of processors that do not share
memory, peripheral devices, or a clock, the operating system manages communications
between all the processes. Multiple processes communicate with one another through
communication lines in the network.
The OS handles routing and connection strategies, and the problems of contention and
security. Following are the major activities of an operating system with respect to
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
Considering a computer system having multiple users and concurrent execution of multiple
processes, the various processes must be protected from each other's activities.
Protection refers to a mechanism or a way to control the access of programs, processes, or
users to the resources defined by a computer system. Following are the major activities of
an operating system with respect to protection −
File Management
These programs create, delete, copy, rename, print, dump, and generally manipulate
files and directories.
Status Information-
Some system programs simply ask information related to the system like date / time/ size of
disc / number of users.
File Modification-
Several text editors may be available to create and modify the content of files stored on disk
or other storage devices. There may also be a special commands to search contents of files
or perform transformation of text.
Communications-
These programs provide the mechanism for operating virtual connections Among processes,
users and computer systems. They allow users to send messages to one another's screen, to
browse web pages, to send electronic mail messages, to log in remotely, or to transfer files
from one machine to another machine.
Some system programs supplied with operating systems are text formatters,
spreadsheet, compilers, web browser, database, games and many more.
System Call :-
For performing any operation an user must have to request for a service call which is also
known as System Call or we can say
Programming interface to the services provided by the operating system
Types of System Calls
Since an user needs to attach many resources, the type of system calls depends on the
user of these resources.
A process is a basic entity in the system. The processes in the system need to be created,
deleted and aborted. Besides this many operations are required on the processes for their
management.
Creation, Deletion, Opening, Closing, Reading, and Writing are some general operations
on files. Similarly for organizing files, there is a directory system and thereby system calls
for managing them
Many system calls exist simply for the purpose of transferring information between the user
program and the operating system. Like -
There is a need for communication among the processes in the system. General operations
are
The system calls may be related to communication between processes either on the same
machine or between processes on different nodes of a network. Thus inter process
communication is provided by the operating system through these communication related
system calls.
Simple Structure
There are many operating systems that have a rather simple structure. These started as small
systems and rapidly expanded much further than their scope. A common example of this is
MS-DOS. It was designed simply for a niche amount for people. There was no indication
that it would become so popular.
It is better that operating systems have a modular structure, unlike MS-DOS. That would
lead to greater control over the computer system and its various applications. The modular
structure would also allow the programmers to hide information as required and implement
internal routines as they see fit without changing the outer specifications.
Layered Structure
One way to achieve modularity in the operating system is the layered approach. In this, the
bottom layer is the hardware and the topmost layer is the user interface.
One problem with the layered structure is that each layer needs to be carefully defined. This
is necessary because the upper layers can only use the functionalities of the layers below
them.
Virtual Machine abstracts the hardware of our personal computer such as CPU, disk drives,
memory, NIC (Network Interface Card) etc, into many different execution environments as
per our requirements, hence giving us a feel that each execution environment is a single
computer. For example, VirtualBox.
When we run different processes on an operating system, it creates an illusion that each
process is running on a different processor having its own virtual memory, with the help of
CPU scheduling and virtual-memory techniques. There are additional features of a process
that cannot be provided by the hardware alone like system calls and a file system. The
virtual machine approach does not provide these additional functionalities but it only
provides an interface that is same as basic hardware. Each process is provided with a virtual
copy of the underlying computer system.
We can create a virtual machine for several reasons, all of which are fundamentally related
to the ability to share the same basic hardware yet can also support different execution
environments, i.e., different operating systems simultaneously.
The main drawback with the virtual-machine approach involves disk systems. Let us
suppose that the physical machine has only three disk drives but wants to support seven
virtual machines. Obviously, it cannot allocate a disk drive to each virtual machine, because
virtual-machine software itself will need substantial disk space to provide virtual memory
and spooling. The solution is to provide virtual disks.
Users are thus given their own virtual machines. After which they can run any of the
operating systems or software packages that are available on the underlying machine. The
virtual-machine software is concerned with multi-programming multiple virtual machines
onto a physical machine, but it does not need to consider any user-support software. This
arrangement can provide a useful way to divide the problem of designing a multi-user
interactive system, into two smaller pieces.
Advantages:
1. There are no protection problems because each virtual machine is completely isolated
from all other virtual machines.
2. Virtual machine can provide an instruction set architecture that differs from real
computers.
3. Easy maintenance, availability and convenient recovery.
Disadvantages:
1. When multiple virtual machines are simultaneously running on a host computer, one
virtual machine can be affected by other running virtual machines, depending on the
workload.
2. Virtual machines are not as efficient as a real one when accessing the hardware.
Unit-2
Process Management
Process Concept:
A program in execution is called a process. In order to accomplish its task, process needs the
computer resources.
There may exist more than one processes in the system which may require the same resource
at the same time. Therefore, the operating system has to manage all the processes and the
resources in a convenient and efficient way.
Some resources may need to be executed by one process at one time to maintain the
consistency otherwise the system can become inconsistent and deadlock may occur.
The operating system is responsible for the following activities in connection with Process
Management
Process State:
When a process executes, it passes through different states. In general, a process can have
one of the following five states at a time.
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 some
input/output.
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.
Process Control Block is a data structure that contains information of the process related to
it. The process control block is also known as a task control block, entry of the process table,
etc.
Scheduling Queues:
The OS maintains all PCBs in Process Scheduling Queues. The OS maintains a separate
queue for each of the process states and PCBs of all processes in the same execution state
are placed in the same queue. When 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.
Schedulers
Schedulers are special system software 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. Schedulers are of three types −
Long-Term Scheduler
Short-Term Scheduler
Medium-Term Scheduler
It is also called as CPU scheduler. Its main objective is to increase system performance in
accordance with the chosen set of criteria. It is the change of ready state to running state of
the process. CPU scheduler selects a process among the processes that are ready to execute
and allocates CPU to one of them.
Short-term schedulers, also known as dispatchers, make the decision of which process to
execute next. Short-term schedulers are faster than long-term schedulers.
Medium-term scheduling is a part of swapping. It removes the processes from the memory.
It reduces the degree of multiprogramming. The medium-term scheduler is in-charge of
handling the swapped out-processes.
A running process may become suspended if it makes an I/O request. A suspended
processes cannot make any progress towards completion. In this condition, to remove the
process from memory and make space for other processes, the suspended process is moved
to the secondary storage. This process is called swapping, and the process is said to be
swapped out or rolled out. Swapping may be necessary to improve the process mix.
5 It selects processes from pool It selects those processes It can re-introduce the process
and loads them into memory which are ready to into memory and execution
for execution execute can be continued.
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.
Context switches are computationally intensive since register and memory state must be
saved and restored. To avoid the amount of context switching time, some hardware systems
employ two or more sets of processor registers. When the process is switched, the
following information is stored for later use.
Program Counter
Scheduling information
Base and limit register value
Currently used register
Changed State
I/O State information
Accounting information
Operation on a Process:
1. Creation: This is the initial step of process execution activity. Process creation
means the construction of a new process for the execution. This might be performed
by system, user or old process itself. There are several events that leads to the
process creation. Some of the such events are following:
a) When we start the computer, system creates several background processes.
b) A user may request to create a new process.
c) A process can create a new process itself while executing.
d) Batch system takes initiation of a batch job.
2. Scheduling/Dispatching: The event or activity in which the state of the process is
changed from ready to running. It means the operating system puts the process from
ready state into the running state. Dispatching is done by operating system when the
resources are free or the process has higher priority than the ongoing process. There
are various other cases in which the process in running state is preempted and
process in ready state is dispatched by the operating system.
3. Blocking: When a process invokes an input-output system call that blocks the
process and operating system put in block mode. Block mode is basically a mode
where process waits for input-output. Hence on the demand of process itself,
operating system blocks the process and dispatches another process to the processor.
Hence, in process blocking operation, the operating system puts the process in
‘waiting’ state.
4. Preemption: When a timeout occurs that means the process hadn’t been terminated
in the allotted time interval and next process is ready to execute, then the operating
system preempts the process. This operation is only valid where CPU scheduling
supports preemption. Basically this happens in priority scheduling where on the
incoming of high priority process the ongoing process is preempted. Hence, in
process preemption operation, the operating system puts the process in ‘ready’ state.
5. Termination: Process termination is the activity of ending the process. In other
words, process termination is the relaxation of computer resources taken by the
process for the execution. Like creation, in termination also there may be several
events that may lead to the process termination. Some of them are:
e) Process completes its execution fully and it indicates to the OS that it has
finished.
f) Operating system itself terminates the process due to service errors.
g) There may be problem in hardware that terminates the process.
h) One process can be terminated by another process.
Many applications are structured as multiple processes, so these multi processes have to able
to interact with each other in order to achieve a common goal. As we have already studied
that operating system isolates the process from each other in order to protect each other’s
memory space, OS controls the amount of CPU each application gets. So some
communication mechanism is required to build without sacrificing the protection. These
mechanisms are called inter-process communication (IPC). Their task is to transfer data/info
between address spaces without sacrificing the protection and isolation that OS provides. As
communication can vary from the continuous stream of data sharing, periodic data sharing, a
single piece of data sharing, etc so the IPC mechanism has to be flexible with good
performance.
Advantage: Advantage of this mechanism is that OS manages both writing and reading
data from the channel and provides APIs. So both process uses the exact same APIs.
Disadvantage: One disadvantage of this mechanism is that data has to first copy from
sending process memory space to shared channel and then back to receiving process
memory space.
Shared Memory IPC: In this mechanism, the OS creates a shared memory channel and
then maps it to each process memory space, and then processes are allowed to read and
write to the channel as if they would do to any memory space that is part of their
memory space.
CPU Scheduling
CPU Scheduling is a process of determining which process will own CPU for execution
while another process is on hold. The main task of CPU scheduling is to make sure that
whenever the CPU remains idle, the OS at least select one of the processes available in the
ready queue for execution. The selection process will be carried out by the CPU scheduler. It
selects one of the processes in memory that are ready for execution.
Preemptive Scheduling
In Preemptive Scheduling, the tasks are mostly assigned with their priorities. Sometimes it is
important to run a task with a higher priority before another lower priority task, even if the
lower priority task is still running. The lower priority task holds for some time and resumes
when the higher priority task finishes its execution.
Non-Preemptive Scheduling
In this type of scheduling method, the CPU has been allocated to a specific process. The
process that keeps the CPU busy will release the CPU either by switching context or
terminating. It is the only method that can be used for various hardware platforms. That's
because it doesn't need special hardware (for example, a timer) like preemptive scheduling.
Maximize:
CPU utilization: CPU utilization is the main task in which the operating system needs to
make sure that CPU remains as busy as possible. It can range from 0 to 100 percent.
However, for the RTOS, it can be range from 40 percent for low-level and 90 percent for the
high-level system.
Throughput: The number of processes that finish their execution per unit time is known
Throughput. So, when the CPU is busy executing the process, at that time, work is being
done, and the work completed per unit time is called Throughput.
Minimize:
Waiting time: Waiting time is an amount that specific process needs to wait in the ready
queue.
Response time: It is an amount to time in which the request was submitted until the first
response is produced.
Dispatcher
It is a module that provides control of the CPU to the process. The Dispatcher should be fast
so that it can run on every context switch. Dispatch latency is the amount of time needed by
the CPU scheduler to stop one process and start another.
Context Switching
Switching to user mode
Moving to the correct location in the newly loaded program.
First Come First Serve is the full form of FCFS. It is the easiest and most simple CPU
scheduling algorithm. In this type of algorithm, the process which requests the CPU gets the
CPU allocation first. This scheduling method can be managed with a FIFO queue.
As the process enters the ready queue, its PCB (Process Control Block) is linked with the
tail of the queue. So, when CPU becomes free, it should be assigned to the process at the
beginning of the queue.
The full form of SRT is Shortest remaining time. It is also known as SJF preemptive
scheduling. In this method, the process will be allocated to the task, which is closest to its
completion. This method prevents a newer ready state process from holding the completion
of an older process.
This method is mostly applied in batch environments where short jobs are required to
be given preference.
This is not an ideal method to implement it in a shared system where the required
CPU time is unknown.
Associate with each process as the length of its next CPU burst. So that operating
system uses these lengths, which helps to schedule the process with the shortest
possible time.
Priority scheduling also helps OS to involve priority assignments. The processes with higher
priority should be carried out first, whereas jobs with equal priorities are carried out on a
round-robin or FCFS basis. Priority can be decided based on memory requirements, time
requirements, etc.
Round-Robin Scheduling
Round robin is the oldest, simplest scheduling algorithm. The name of this algorithm comes
from the round-robin principle, where each person gets an equal share of something in turn.
It is mostly used for scheduling algorithms in multitasking. This algorithm method helps for
starvation free execution of processes.
SJF is a full form of (Shortest job first) is a scheduling algorithm in which the process with
the shortest execution time should be selected for execution next. This scheduling method
can be preemptive or non-preemptive. It significantly reduces the average waiting time for
other processes awaiting execution.
This algorithm separates the ready queue into various separate queues. In this method,
processes are assigned to a queue based on a specific property of the process, like the
process priority, size of the memory, etc.
However, this is not an independent scheduling OS algorithm as it needs to use other types
of algorithms in order to schedule the jobs.
Process synchronization
When two or more process cooperates with each other, their order of execution must be
preserved otherwise there can be conflicts in their execution and inappropriate outputs can
be produced.
A cooperative process is the one which can affect the execution of other process or can be
affected by the execution of other process. Such processes need to be synchronized so that
their order of execution can be guaranteed.
Race Condition
A Race Condition typically occurs when two or more processes try to read, write and
possibly make the decisions based on the memory that they are accessing concurrently.
Critical Section
The regions of a program that try to access shared resources and may cause race conditions
are called critical section. To avoid race condition among the processes, we need to assure
that only one process at a time can execute within the critical section.
Critical Section is the part of a program which tries to access shared resources. That resource
may be any resource in a computer like a memory location, Data structure, CPU or any IO
device.
The critical section cannot be executed by more than one process at the same time; operating
system faces the difficulties in allowing and disallowing the processes from entering the
critical section.
The critical section problem is used to design a set of protocols which can ensure that the
Race condition among the processes will never arise.
In order to synchronize the cooperative processes, our main task is to solve the critical
section problem. We need to provide a solution in such a way that the following conditions
can be satisfied.
In Process Synchronization, critical section plays the main role so that the problem must be
solved. Here are some widely used methods to solve the critical section problem.
Peterson Solution
PROCESS Pi
FLAG[i] = true
while( (turn != i) AND (CS is !free) ){ wait;
}
CRITICAL SECTION FLAG[i] = false
turn = j; //choose another process to go to CS
Mutex Locks
Synchronization hardware not simple method to implement for everyone, so strict software
method known as Mutex Locks was also introduced.
In this approach, in the entry section of code, a LOCK is obtained over the critical resources
used inside the critical section. In the exit section that lock is released.
Semaphore Solution
It uses two atomic operations, 1) wait, and 2) signal for the process synchronization.
Example
WAIT ( S ):
while ( S <= 0 );
S = S - 1;
SIGNAL ( S ):
S = S + 1;
Unit 3
Deadlock is a situation where a set of processes are blocked because each process is holding a
resource and waiting for another resource acquired by some other process.
Consider an example when two trains are coming toward each other on the same track and
there is only one track, none of the trains can move once they are in front of each other. A
similar situation occurs in operating systems when there are two or more processes that hold
some resources and wait for resources held by other(s). For example, in the below diagram,
Process 1 is holding Resource 1 and waiting for resource 2 which is acquired by process 2, and
process 2 is waiting for resource 1.
Mutual Exclusion
There should be a resource that can only be held by one process at a time. In the
diagram below, there is a single instance of Resource 1 and it is held by Process 1
only.
No Preemption
A resource cannot be preempted from a process by force. A process can only release
a resource voluntarily. In the diagram below, Process 2 cannot preempt Resource 1
from Process 1. It will only be released when Process 1 relinquishes it voluntarily
after its execution is complete.
Circular Wait
A process is waiting for the resource held by the second process, which is waiting for
the resource held by the third process and so on, till the last process is waiting for a
resource held by the first process. This forms a circular chain. For example: Process
1 is allocated Resource2 and it is requesting Resource 1. Similarly, Process 2 is
allocated Resource 1 and it is requesting Resource 2. This forms a circular wait loop.
Resource-Allocation Graph
In some cases deadlocks can be understood more clearly through the use of Resource-
Allocation Graphs, having the following properties:
A set of resource categories, { R1, R2, R3, . . ., RN }, which appear as square nodes on
the graph. Dots inside the resource nodes indicate specific instances of the resource. (
E.g. two dots might represent two laser printers. )
Request Edges - A set of directed arcs from Pi to Rj, indicating that process Pi has
requested Rj, and is currently waiting for that resource to become available.
Assignment Edges - A set of directed arcs from Rj to Pi indicating that resource Rj has
been allocated to process Pi, and that Pi is currently holding resource Rj.
Note that a request edge can be converted into an assignment edge by reversing the
direction of the arc when the request is granted. to the category box, For example:
If a resource-allocation graph does contain cycles AND each resource category contains
only a single instance, then a deadlock exists.
If a resource category contains more than one instance, then the presence of a cycle in
the resource-allocation graph indicates the possibility of a deadlock, but does not
guarantee one
1. Deadlock Ignorance
Deadlock Ignorance is the most widely used approach among all the mechanism. This is
being used by many operating systems mainly for end user uses. In this approach, the
Operating system assumes that deadlock never occurs. It simply ignores deadlock. This
approach is best suitable for a single end user system where User uses the system only for
browsing and other normal stuff.
In these types of systems, the user has to simply restart the computer in the case of deadlock.
Windows and Linux are mainly using this approach.
2. Deadlock prevention
Deadlock happens only when Mutual Exclusion, hold and wait, No preemption and circular
wait holds simultaneously. If it is possible to violate one of the four conditions at any time
then the deadlock can never occur in the system.
The idea behind the approach is very simple that we have to fail one of the four conditions
but there can be a big argument on its physical implementation in the system.
3. Deadlock avoidance
In deadlock avoidance, the operating system checks whether the system is in safe state or in
unsafe state at every step which the operating system performs. The process continues until
the system is in safe state. Once the system moves to unsafe state, the OS has to backtrack
one step.
In simple words, The OS reviews each allocation so that the allocation doesn't cause the
deadlock in the system.
This approach let the processes fall in deadlock and then periodically check whether
deadlock occur in the system or not. If it occurs then it applies some of the recovery methods
to the system to get rid of deadlock.
Deadlock Prevention
We can prevent Deadlock by eliminating any of the above four conditions.
Deadlock Avoidance
In deadlock avoidance, the request for any resource will be granted if the resulting state of
the system doesn't cause deadlock in the system. The state of the system will continuously
be checked for safe and unsafe states.
Safe State
A state is safe if the system can allocate all resources requested by all processes ( up
to their stated maximums ) without entering a deadlock state.
More formally, a state is safe if there exists a safe sequence of processes { P0, P1,
P2, ..., PN } such that all of the resource requests for Pi can be granted using the
resources currently allocated to Pi and all processes Pj where j < i. ( I.e. if all the
processes prior to Pi finish and free up their resources, then Pi will be able to finish
also, using the resources that they have freed up. )
If a safe sequence does not exist, then the system is in an unsafe state,
which MAY lead to deadlock. ( All safe states are deadlock free, but not all unsafe
states lead to deadlocks. )
For example, consider a system with 12 tape drives, allocated as follows. Is this a
safe state? What is the safe sequence?
P0 10 5
P1 4 2
P2 9 2
What happens to the above table if process P2 requests and is granted one more tape
drive?
Key to the safe state approach is that when a request is made for resources, the
request is granted only if the resulting allocation state is a safe one.
Resource allocation graph
This graph is also kind of graphical bankers' algorithm where a process is denoted by a
circle Pi and resources is denoted by a rectangle RJ (.dots) inside the resources represents
copies.
Presence of a cycle in the resources allocation graph is necessary but not sufficient condition
for detection of deadlock. If the type of every resource has exactly one copy than the
presence of cycle is necessary as well as sufficient condition for detection of deadlock.
This is in unsafe state (cycle exist) if P1 request P2 and P2 request R1 then deadlock will
occur.
Now that we have a tool for determining if a particular state is safe or not, we are
now ready to look at the Banker's algorithm itself.
This algorithm determines if a new request is safe, and grants it only if it is safe to do
so.
When a request is made ( that does not exceed currently available resources ),
pretend it has been granted, and then see if the resulting state is a safe one. If so,
grant the request, and if not, deny the request, as follows:
1. Let Request[ n ][ m ] indicate the number of resources of each type currently
requested by processes. If Request[ i ] > Need[ i ] for any process i, raise an
error condition.
2. If Request[ i ] > Available for any process i, then that process must wait for
resources to become available. Otherwise the process can continue to step 3.
3. Check to see if the request can be granted safely, by pretending it has been
granted and then seeing if the resulting state is safe. If so, grant the request,
and if not, then the process must wait until its request can be granted
safely.The procedure for granting a request ( or pretending to for testing
purposes ) is:
Available = Available - Request
Allocation = Allocation + Request
Need = Need - Request
Example
When the system is in deadlock then one method is to inform the operates and then operator
deal with deadlock manually and the second method is system will automatically recover
from deadlock. There are two ways to recover from deadlock:
Process termination:
Deadlock can be eliminated by aborting a process. Abort all deadlock process. Abort is
processed at a time until the deadlock cycle is eliminated. This can help to recover the
system from file deadlock.
Resources preemption:
To eliminate deadlock using resources preemption, we prompt the same resources pas
processes and give these resources to another process until the deadlock cycle is broken.
Here a process is partially rollback until the last checkpoint or and hen detection algorithm is
executed.
Unit 4
Memory management is concerned with managing the primary memory. Memory consists
of array of bytes or words each with their own address. The instructions are fetched from the
memory by the CPU based on the value program counter.
Programs are stored on the secondary storage disks as binary executable files. When the
programs are to be executed they are brought in to the main memory and placed within a
process. The collection of processes on the disk waiting to enter the main memory forms the
input queue. One of the processes which are to be executed is fetched from the queue and
placed in the main memory. During the execution it fetches instruction and data from main
memory. After the process terminates it returns back the memory space. During execution
the process will go through different steps and in each step the address is represented in
different ways. In source program the address is symbolic. The compiler converts the
symbolic address to re-locatable address. The loader will convert this re-locatable address to
absolute address.Binding of instructions and data can be done at any step along the way:
Compile time:-If we know whether the process resides in memory then absolute code can
be generated. If the static address changes then it is necessary to re-compile the code from
the beginning.
Load time:-If the compiler doesn’t know whether the process resides in memory then it
generates the re-locatable code. In this the binding is delayed until the load time.
Execution time:-If the process is moved during its execution from one memory segment to
another then the binding is delayed until run time. Special hardware is used for this. Most of
the general purpose operating system uses this method
The address generated by the CPU is called logical address or virtual address. The address
seen by the memory unit i.e., the one loaded in to the memory register is called the physical
address. Compile time and load time address binding methods generate some logical and
physical address. The execution time addressing binding generate different logical and
physical address. Set of logical address space generated by the programs is the logical
address space. Set of physical address corresponding to these logical addresses is the
physical address space. The mapping of virtual address to physical address during run time
is done by the hardware device called memory management unit (MMU). The base register
is also called re-location register. Value of the re-location register is added to every address
generated by the user process at the time it is sent to memory. Dynamic re-location using a
re-location registers.
For a process to be executed it should be loaded in to the physical memory. The size of the
process is limited to the size of the physical memory. Dynamic loading is used to obtain
better memory utilization. In dynamic loading the routine or procedure will not be loaded
until it is called. Whenever a routine is called, the calling routine first checks whether the
called routine is already loaded or not. If it is not loaded it cause the loader to load the
desired program in to the memory and updates the programs address table to indicate the
change and control is passed to newly called routine.
Advantage: Gives better memory utilization. Unused routine is never loaded. Do not need
special operating system support. This method is useful when large amount of codes are
needed to handle in frequently occurring cases.
Some operating system supports only the static linking. In dynamic linking only the main
program is loaded in to the memory. If the main program requests a procedure, the
procedure is loaded and the link is established at the time of references. This linking is
postponed until the execution time. With dynamic linking a “stub” is used in the image of
each library referenced routine. A “stub” is a piece of code which is used to indicate how to
locate the appropriate memory resident library routine or how to load library if the routine is
not already present. When “stub” is executed it checks whether the routine is present is
memory or not. If not it loads the routine in to the memory. This feature can be used to
update libraries i.e., library is replaced by a new version and all the programs can make use
of this library. More than one version of the library can be loaded in memory at a time and
each program uses its version of the library. Only the programs that are compiled with the
new version are affected by the changes incorporated in it. Other programs linked before
new version is installed will continue using older libraries this type of system is called
“shared library”.
Swapping
Swapping is a technique of temporarily removing inactive programs from the memory of the
system. A process can be swapped temporarily out of the memory to a backing store and
then brought back in to the memory for continuing the execution. This process is called
swapping. Eg:-In a multi-programming environment with a round robin CPU scheduling
whenever the time quantum expires then the process that has just finished is swapped out
and a new process swaps in to the memory for execution.
One of the simplest method for memory allocation is to divide memory in to several fixed
partition. Each partition contains exactly one process. The degree of multi-programming
depends on the number of partitions. In multiple partition method, when a partition is free,
process is selected from the input queue and is loaded in to free partition of memory. When
process terminates, the memory partition becomes available for another process. Batch OS
uses the fixed size partition scheme.The OS keeps a table indicating which part of the
memory is free and is occupied. When the process enters the system it will be loaded in to
the input queue. The OS keeps track of the memory requirement of each process and the
amount of memory available and determines which process to allocate the memory. When a
process requests, the OS searches for large hole for this process, hole is a large block of free
memory available. If the hole is too large it is split in to two. One part is allocated to the
requesting process and other is returned to the set of holes. The set of holes are searched to
determinewhich hole is best to allocate. There are three strategies to select a free hole:
First bit:-Allocates first hole that is big enough. This algorithm scans memory from
the beginning and selects the first available block that is large enough to hold the
process.
Best bit:-It chooses the hole i.e., closest in size to the request. It allocates the smallest
hole i.e., big enough to hold the process.
Worst fit:-It allocates the largest hole to the process request. It searches for the
largest hole in the entire list.
Fragmentation:
In Internal Fragmentation there is wasted space internal to a portion due to the fact that
block of data loaded is smaller than the partition. Eg:-If there is a block of 50kb and if the
process requests 40kb and if the block is allocated to the process then there will be 10kb of
memory left.
External Fragmentation exists when there is enough memory space exists to satisfy the
request, but it not contiguous i.e., storage is fragmented in to large number of small holes.
External Fragmentation may be either minor or a major problem.
One solution for over-coming external fragmentation is compaction. The goal is to move all
the free memory together to form a large block. Compaction is not possible always. If the
relocation is static and is done at load time then compaction is not possible. Compaction is
possible if the re-location is dynamic and done at execution time.
Another possible solution to the external fragmentation problem is to permit the logical
address space of a process to be non-contiguous, thus allowing the process to be allocated
physical memory whenever the latter is available.
Paging
As mentioned above, the memory management function called paging specifies storage
locations to the CPU as additional memory, called virtual memory. The CPU cannot directly
access storage disk, so the MMU emulates memory by mapping pages to frames that are in
RAM.
Before we launch into a more detailed explanation of pages and frames, let’s define some
technical terms.
Virtual address: The CPU generates a virtual address for each active process. The
MMU maps the virtual address to a physical location in RAM and passes the address
to the bus. A virtual address space is the range of virtual addresses under CPU control.
Physical address: The physical address is a location in RAM. The physical address
space is the set of all physical addresses corresponding to the CPU’s virtual addresses.
A physical address space is the range of physical addresses under MMU control.
A page table stores the definition of each page. When an active process requests data, the
MMU retrieves corresponding pages into frames located in physical memory for faster
processing. The process is called paging.
The MMU uses page tables to translate virtual addresses to physical ones. Each table entry
indicates where a page is located: in RAM or on disk as virtual memory. Tables may have a
single or multi-level page table such as different tables for applications and segments.
However, constant table lookups can slow down the MMU. A memory cache called the
Translation Lookaside Buffer (TLB) stores recent translations of virtual to physical
addresses for rapid retrieval. Many systems have multiple TLBs, which may reside at
different locations, including between the CPU and RAM, or between multiple page table
levels.
Different frame sizes are available for data sets with larger or smaller pages and matching-
sized frames. 4KB to 2MB are common sizes, and GB-sized frames are available in high-
performance servers.
Segmentation
The process known as segmentation is a virtual process that creates address spaces of
various sizes in a computer system, called segments. Each segment is a different virtual
address space that directly corresponds to process objects.
When a process executes, segmentation assigns related data into segments for faster
processing. The segmentation function maintains a segment table that includes physical
addresses of the segment, size, and other data.
Each segment stores the processes primary function, data structures, and utilities. The CPU
keeps a segment map table for every process and memory blocks, along with segment
identification and memory locations.
The CPU generates virtual addresses for running processes. Segmentation translates the
CPU-generated virtual addresses into physical addresses that refer to a unique physical
memory location. The translation is not strictly one-to-one: different virtual addresses can
map to the same physical address.
Segmented Paging
Some modern computers use a function called segmented paging. Main memory is divided
into variably-sized segments, which are then divided into smaller fixed-size pages on disk.
Each segment contains a page table, and there are multiple page tables per process.
Each of the tables contains information on every segment page, while the segment table has
information about every segment. Segment tables are mapped to page tables, and page tables
are mapped to individual pages within a segment.
Advantages include less memory usage, more flexibility on page sizes, simplified memory
allocation, and an additional level of data access security over paging. The process does not
cause external fragmentation.
Paging Advantages
On the programmer level, paging is a transparent function and does not require
intervention.
No external fragmentation.
Longer memory lookup times than segmentation; remedy with TLB memory
caches.
Segmentation Advantages
No internal fragmentation.
Average segment sizes are larger than most page sizes, which allows segments to
store more process data.
Segment tables are smaller than page tables, and takes up less memory.
Segmentation Disadvantages
Size:
Paging: Fixed block size for pages and frames. Computer hardware determines
page/frame sizes.
Segmentation: Variable size segments are user-specified.
Fragmentation:
Tables:
Paging: Page tables direct the MMU to page location and status. This is a slower
process than segmentation tables, but TLB memory cache accelerates it.
Virtual Memory
Figure below shows the general layout of virtual memory, which can be much larger than
physical memory:
Virtual memory also allows the sharing of files and memory by multiple processes, with
several benefits:
System libraries can be shared by mapping them into the virtual address space of
more than one process.
Processes can also share virtual memory by mapping the same block of memory to
more than one process.
Process pages can be shared during a fork( ) system call, eliminating the need to
copy all of the pages of the original ( parent ) process.
Demand Paging
The basic idea behind demand paging is that when a process is swapped in, its pages are
not swapped in all at once. Rather they are swapped in only when the process needs them.
(on demand ) This is termed a lazy swapper, although a pager is a more accurate term.
Page Replacement
In order to make the most use of virtual memory, we load several processes into
memory at the same time. Since we only load the pages that are actually needed by
each process at any given time, there is room to load many more processes than if we
had to load in the entire process.
However memory is also needed for other purposes ( such as I/O buffering ), and
what happens if some process suddenly decides it needs more pages and there
aren't any free frames available? There are several possible solutions to consider:
1. Adjust the memory used by I/O buffering, etc., to free up some frames for user
processes. The decision of how to allocate memory for I/O versus user processes is a
complex one, yielding different policies on different systems. ( Some allocate a fixed
amount for I/O, and others let the I/O system contend for memory along with everything
else. )
2. Put the process requesting more pages into a wait queue until some free frames become
available.
3. Swap some process out of memory completely, freeing up its page frames.69
4. Find some page in memory that isn't being used right now, and swap that page only out
to disk, freeing up a frame that can be allocated to the process requesting it. This is
known as page replacement, and is the most common solution.
Page Replacement Algorithms
The page replacement algorithm decides which memory page is to be replaced. The
process of replacement is sometimes called swap out or write to disk. Page replacement
is done when the requested page is not found in the main memory (page fault).
There are various page replacement algorithms. Each algorithm has a different method by
which the pages can be replaced.
Device management in operating system implies the management of the I/O devices such as
a keyboard, magnetic tape, disk, printer, microphone, USB ports, scanner, and camcorder
etc.as well as the supporting units like control channels. The basics of I/O devices can fall
into 3 categories:
Block device: it stores information in fixed-size block, each one with its own address.Fr
example, disks.
Character device: it’s delivers or accepts a stream of characters. The individual characters
are not addressable. For example printers, keyboards etc.
Network device: For transmitting data packets.
The main functions of device management in the operating system
An operating system or the OS manages communication with the devices through their
respective drivers. The operating system component provides a uniform interface to access
devices of varied physical attributes. For device management in operating system:
Keep tracks of all devices and the program which is responsible to perform this is
called I/O controller.
Monitoring the status of each device such as storage drivers, printers and other
peripheral devices.
Enforcing preset policies and taking a decision which process gets the device when
and for how long.
Allocates and Deallocates the device in an efficient way.De-allocating them at two
levels: at the process level when I/O command has been executed and the device is
temporarily released, and at the job level, when the job is finished and the device is
permanently released.
Optimizes the performance of individual devices.
Types of devices
The OS peripheral devices can be categorized into 3: Dedicated, Shared, and Virtual. The
differences among them are the functions of the characteristics of the devices as well as how
they are managed by the Device Manager.
Dedicated devices
Such type of devices in the device management in operating system are dedicated or
assigned to only one job at a time until that job releases them. Devices like printers, tape
drivers, plotters etc. demand such allocation scheme since it would be awkward if several
users share them at the same point of time. The disadvantages of such kind f devices s the
inefficiency resulting from the allocation of the device to a single user for the entire duration
of job execution even though the device is not put to use 100% of the time.
Shared devices
These devices can be allocated o several processes. Disk-DASD can be shared among
several processes at the same time by interleaving their requests. The interleaving is
carefully controlled by the Device Manager and all issues must be resolved on the basis of
predetermined policies.
Virtual Devices
These devices are the combination of the first two types and they are dedicated devices
which are transformed into shared devices. For example, a printer converted into a shareable
device via spooling program which re-routes all the print requests to a disk. A print job is
not sent straight to the printer, instead, it goes to the disk(spool)until it is fully prepared with
all the necessary sequences and formatting, then it goes to the printers. This technique can
transform one printer into several virtual printers which leads to better performance and use.
Storage Devices
There are many types of storage devices, each with their own benefits and drawbacks.
Device Drivers:
Spooling
Simultaneous peripheral operation online, acronym for this is Spooling. A spool is a kind
of buffer that holds the jobs for a device till the device is ready to accept the job. Spooling
considers disk as a huge buffer that can store as many jobs for the device till the output
devices are ready to accept them.
In spooling, I/O of one job is overlapped with the computation of another job. For example,
a spooler at a time may read input of one job, and at the same time, it may also print the
output of another job.
Spooling can also process data at the remote sites. The spooler only has to notify when a
process gets completed at the remote site so that spooler can spool next process to the
remote side device.
Spooling increases the performance of the system by increasing the working rate of the
devices. It naturally leads to multiprogramming.
Buffering
Before discussing buffering, let us discuss, what is the buffer? The buffer is an area in
the main memory that is used to store or hold the data temporarily that is being transmitted
either between two devices or between a device or an application. In simple words, buffer
temporarily stores data that is being transmitted from one place to another. The act of storing
data temporarily in the buffer is called buffering.
There are three reasons behind buffering of data, first is it helps in matching speed between
two devices, between which the data is transmitted. For example, a hard disk has to store the
file received from the modem.
Now, as we know the transmission speed of a modem is slow, as compared to the hard disk.
So bytes coming from the modem is accumulated in the buffer space, and when all the bytes
of a file has arrived at the buffer, the entire data is written to the hard disk in a single
operation.
Secondly, it helps the devices with different data transfer size to get adapted to each other.
It helps devices to manipulate data before sending or receiving. In computer networking, the
large message is fragmented into the small fragments and sent over the network. At the
receiving end, the fragments are accumulated in the buffer and reassembled to form the
complete large message.
The third use of buffering is that it also supports copy semantics. With copy semantics, the
version of data in the buffer is guaranteed to be the version of data at the time of system call
irrespective of any subsequent change to data in the buffer. Buffering increases the
performance of the device. It overlaps the i/o of one job with the computation of the same
job.
Basic Spooling overlap the I/O of one job Buffer overlaps the I/O of one job
with the computation of another with the computation of the same
job. job.
A file can be defined as a data structure which stores the sequence of records. Files are
stored in a file system, which may exist on a disk or in the main memory. Files can be
simple (plain text) or complex (specially-formatted).
The collection of files is known as Directory. The collection of directories at the different
levels, is known as File System.
File System provide efficient access to the disk by allowing data to be stored, located and
retrieved in a convenient way. A file System must be able to store the file, locate the file and
retrieve the file.
Most of the Operating Systems use layering approach for every task including file systems.
Every layer of the file system is responsible for some activities.
1. Create
Creation of the file is the most important operation on the file. Different types of files are
created by different methods for example text editors are used to create a text file, word
processors are used to create a word file and Image editors are used to create the image files.
2. Write
Writing the file is different from creating the file. The OS maintains a write pointer for every
file which points to the position in the file from which, the data needs to be written.
3. Read
Every file is opened in three different modes : Read, Write and append. A Read pointer is
maintained by the OS, pointing to the position up to which, the data has been read.
4. Re-position
Re-positioning is simply moving the file pointers forward or backward depending upon the
user's requirement. It is also called as seeking.
5. Delete
Deleting the file will not only delete all the data stored inside the file, It also deletes all the
attributes of the file. The space which is allocated to the file will now become available and
can be allocated to the other files.
6. Truncate
Truncating is simply deleting the file except deleting attributes. The file is not completely
deleted although the information stored inside the file get replaced.
1. Physical files:
Physical files contain the actual data that is stored on a system, and a description of how data
is to be presented to or received from a program. They contain only one record format, and
one or more members. Records in database files can be described using either a field level
description or record level description.
A field-level description describes the fields in the record to the system. Database files that
are created with field level descriptions are referred to as externally described files.
2. Logical files:
Logical files do not contain data. They contain a description of records that are found in one
or more physical files. A logical file is a view or representation of one or more physical
files. Logical files that contain more than one format are referred to as multi-format logical
files.
Logical Storage Views – viewed by users are a collection of files organized within directories
and storage volumes.
Logical file structure is independent of its physical implementation.
Logical file structure “ignores”.
Physical storage allocations – records can be stored in separate file locations. Data access
methods and Data encoding methods.
Physical Storage Views – a collection of physical storage locations organized as a linear
address space.
File is subdivided into records.
Record usually contains information about a single customer, thing such as a product in
inventory, or an event.
Records are divided into fields.
Fields are individual units of data.
Sequential Access
Most of the operating systems access the file sequentially. In other words, we can say that
most of the files need to be accessed sequentially by the operating system.
In sequential access, the OS read the file word by word. A pointer is maintained which
initially points to the base address of the file. If the user wants to read first word of the file
then the pointer provides that word to the user and increases its value by 1 word. This
process continues till the end of the file.
Modern word systems do provide the concept of direct access and indexed access but the
most used method is sequential access due to the fact that most of the files such as text files,
audio files, video files, etc need to be sequentially accessed.
Direct Access
The Direct Access is mostly required in the case of database systems. In most of the cases,
we need filtered information from the database. The sequential access can be very slow and
inefficient in such cases.
Suppose every block of the storage stores 4 records and we know that the record we needed
is stored in 10th block. In that case, the sequential access will not be implemented because it
will traverse all the blocks in order to access the needed record.
Direct access will give the required result despite of the fact that the operating system has to
perform some complex tasks such as determining the desired block number. However, that
is generally implemented in database applications.
Indexed Access
If a file can be sorted on any of the filed then an index can be assigned to a group of certain
records. However, A particular record can be accessed by its index. The index is nothing but
the address of a record in the file.
In index accessing, searching in a large database became very quick and easy but we need to
have some extra space in the memory to store the index value.
A file system is responsible to allocate the free blocks to the file therefore it has to keep
track of all the free blocks present in the disk. There are mainly two approaches by using
which, the free blocks in the disk are managed.
1. Bit Vector
In this approach, the free space list is implemented as a bit map vector. It contains the
number of bits where each bit represents each block.
If the block is empty then the bit is 1 otherwise it is 0. Initially all the blocks are empty
therefore each bit in the bit map vector contains 1.
LAs the space allocation proceeds, the file system starts allocating blocks to the files and
setting the respective bit to 0.
2. Linked List
It is another approach for free space management. This approach suggests linking together
all the free blocks and keeping a pointer in the cache which points to the first free block.
Therefore, all the free blocks on the disks will be linked together with a pointer. Whenever a
block gets allocated, its previous free block will be linked to its next free block.
Allocation Methods
There are various methods which can be used to allocate disk space to the files. Selection of
an appropriate allocation method will significantly affect the performance and efficiency of
the system. Allocation method provides a way in which the disk will be utilized and the files
will be accessed.
1. Contiguous Allocation.
2. Linked Allocation
3. Indexed Allocation
Contiguous Allocation
If the blocks are allocated to the file in such a way that all the logical blocks of the file get
the contiguous physical block in the hard disk then such allocation scheme is known as
contiguous allocation.
In the image shown below, there are three files in the directory. The starting block and the
length of each file are mentioned in the table. We can check in the table that the contiguous
blocks are assigned to each file as per its need.
Advantages
1. It is simple to implement.
2. We will get Excellent read performance.
3. Supports Random Access into files.
Disadvantages
Linked Allocation
Linked List allocation solves all problems of contiguous allocation. In linked list allocation,
each file is considered as the linked list of disk blocks. However, the disks blocks allocated
to a particular file need not to be contiguous on the disk. Each disk block allocated to a file
contains a pointer which points to the next disk block allocated to the same file.
Advantages
Disadvantages
File allocation table tries to solve as many problems as possible but leads to a drawback. The
more the number of blocks, the more will be the size of FAT.
Therefore, we need to allocate more space to a file allocation table. Since, file allocation
table needs to be cached therefore it is impossible to have as many space in cache. Here we
need a new technology which can solve such problems.
Instead of maintaining a file allocation table of all the disk pointers, Indexed allocation
scheme stores all the disk pointers in one of the blocks called as indexed block. Indexed
block doesn't hold the file data, but it holds the pointers to all the disk blocks allocated to
that particular file. Directory entry will only contain the index block address.
Advantages
Disadvantages
History of Linux:
The History of Linux began in 1991 with the beginning of a personal project by a Finland
student Linus Torvalds to create a new free operating system kernel. Since then, the
resulting Linux kernel has been marked by constant growth throughout history.
In the year 1991, Linux was introduced by a Finland student Linus Torvalds.
Hewlett Packard UNIX(HP-UX) 8.0 was released.
In the year 1992, Hewlett Packard 9.0 was released.
In the year 1993, NetBSD 0.8 and FreeBSD 1.0 released.
In the year 1994, Red Hat Linux was introduced, Caldera was founded by Bryan Sparks
and Ransom Love and NetBSD1.0 Released.
In the year 1995, FreeBSD 2.0 and HP UX 10.0 were released.
In the year 1996, K Desktop Environment was developed by Matthias Ettrich.
In the year 1997, HP-UX 11.0 was released.
In the year 1998, the fifth generation of SGI Unix i.e IRIX 6.5, Sun Solaris 7 operating
system, and Free BSD 3.0 was released.
In the year 2000, the agreement of Caldera Systems with the SCO server software
division and the professional services division was announced.
In the year 2001, Linus Torvalds released the Linux 2.4 version source code.
In the year 2001, Microsoft filed a trademark suit against Lindows.com
In the year 2004, Lindows name was changed to Linspire.
In the year 2004, the first release of Ubuntu was released.
In the year 2005, The project, openSUSE began a free distribution from Novell’s
community.
In the year 2006, Oracle released its own distribution of Red Hat.
In the year 2007, Dell started distributing laptops with Ubuntu pre-installed in it.
In the year 2011, the Linux kernel 3.0 version was released.
In the year 2013, Google Linux-based Android claimed 75% of the smartphone market
share, in terms of the number of phones shipped.
In the year 2014, Ubuntu claimed 22,000,000 users.
The Linux Distributions are listed below.
Debian Linux.
Arch Linux
Gentoo Linux.
Kali Linux Distribution
Ubuntu Linux.
Fedora Linux Distribution.
Linux Mint Desktop.
OpenSUSE
RHEL Linux Distribution.
CentOS Linux Distribution.
The Linux Operating System’s architecture primarily has these components: the Kernel,
Hardware layer, System library, Shell, and System utility.
Architecture of Linux
1). The kernel is the core part of the operating system, which is responsible for all the major
activities of the LINUX operating system. This operating system consists of different
modules and interacts directly with the underlying hardware. The kernel offers the required
abstraction to hide application programs or low-level hardware details to the system. The
types of Kernels are as follows:
Monolithic Kernel
Microkernels
Exo kernels
Hybrid kernels
2). System libraries are special functions, that are used to implement the functionality of the
operating system and do not require code access rights of kernel modules.
3). System Utility programs are liable to do individual and specialized-level tasks.
4).The hardware layer of the LINUX operating system consists of peripheral devices such as
RAM, HDD, CPU.
5). The shell is an interface between the user and the kernel, and it affords services of the
kernel. It takes commands from the user and executes the kernel’s functions. The Shell is
present in different types of operating systems, which are classified into two types:
command-line shells and graphical shells.
The command-line shells provide a command-line interface, while the graphical line shells
provide a graphical user interface. Though both shells perform operations, the graphical user
interface shells perform slower than the command line interface shells. Types of shells are
classified into four:
Korn shell
Bourne shell
C shell
POSIX shell
Features
Open Source
Heavily Documented for beginners
Security
Multiple Desktop Support
Multitasking
Free
Installation
Lightweight
Compatibility
Stability
Networking
Performance
Privacy
Flexibility
Community Support
Software Updates
Suitable for programmers
Distributions/ Distros
Graphical User Interface
Live CD/USB
The file name of Linux is case sensitive The file name of Windows is case insensitive
It is free It is commercial
To separate the directories, a forward slash is used To separate the directories, the backslash is used
Linux is extensively used to hack the systems Windows do not offer much effectiveness in hacking.
The considered files in Linux are CD-ROMs, hard The considered devices in windows are Hard drives,
drives, & printers printers, CD-ROMs.
The user account types in Linux are 3 types like The user account types in Windows are four types
Regular, Root & Service Account like Administrator, Standard, Child, & Guest
The superuser like Root user of Linux includes all The administrator user of Windows includes all
administrative human rights. administrative human rights of computers.
For each user, his home directory is created like In windows OS, the default home directory is My
home or username. Documents
Linux Commands:
cat
This command outputs the contents of a text file. You can use it to read brief files or to
concatenate files together.
cat myfile
Because cat displays text without pausing, its output may quickly scroll off your screen. Use
the less command or an editor for reading longer text files.
cd
This command changes your current directory location. By default, your Unix login session
begins in your home directory.
cd myfiles
cd /home/dvader/empire_docs
cd ..
cd /
cd
chmod
This command changes the permission information associated with a file. Every file
(including directories, which Unix treats as files) on a Unix system is stored with records
indicating who has permission to read, write, or execute the file, abbreviated as r, w, and x.
These permissions are broken down for three categories of user: first, the owner of the file;
second, a group with which both the user and the file may be associated; and third, all other
users. These categories are abbreviated as u for owner (or user), g for group, and o for other.
To allow yourself to execute a file that you own named myfile, enter:
To allow anyone who has access to the directory in which myfile is stored to read or
execute myfile, enter:
You can view the permission settings of a file using the ls command, described below.
Be careful with the chmod command. If you tamper with the directory permissions of your
home directory, for example, you could lock yourself out or allow others unrestricted access
to your account and its contents.
cp
This command copies a file, preserving the original and creating an identical copy. If you
already have a file with the new name, cp will overwrite and destroy the duplicate. For this
reason, it's safest to always add -i after the cp command, to force the system to ask for your
approval before it destroys any files. The general syntax for cp is:
cp -i oldfile newfile
cp -i /home/dvader/notes/meeting1 .
The . (period) indicates the current directory as destination, and the -i ensures that if there is
another file named meeting1 in the current directory, you will not overwrite it by accident.
To copy a file named oldfile in the current directory to the new name newfile in
the mystuff subdirectory of your home directory, enter:
cp -i oldfile ~/mystuff/newfile
date
The date command displays the current day, date, time, and year.
date
kill
Use this command as a last resort to destroy any jobs or programs that you suspended and
are unable to restart. Use the jobs command to see a list of suspended jobs. To kill
suspended job number three, for example, enter:
kill %3
Now check the jobs command again. If the job has not been cancelled, harsher measures
may be necessary. Enter:
kill -9 %3
To read the contents of a file named textfile in the current directory, enter:
less textfile
The less utility is often used for reading the output of other commands. For example, to read
the output of the ls command one screen at a time, enter:
ls -la | less
In both examples, you could substitute more for less with similar results. To exit
either less or more, press q. To exit less after viewing the file, press q.
ls
This command will list the files stored in a directory. To see a brief, multi-column list of the
files in the current directory, enter:
ls
To also see "dot" files (configuration files that begin with a period, such as .login), enter:
ls -a
To see the file permissions, owners, and sizes of all files, enter:
ls -la
If the listing is long and scrolls off your screen before you can read it, combine ls with
the less utility, for example:
ls -la | less
mkdir
This command will make a new subdirectory.
mkdir mystuff
To create a subdirectory named morestuff in the existing directory named /tmp, enter:
mkdir /tmp/morestuff
mv
This command will move a file. You can use mv not only to change the directory location of
a file, but also to rename files. Unlike the cp command, mv will not preserve the original
file.
As with the cp command, you should always use -i to make sure you do not overwrite an
existing file.
To rename a file named oldname in the current directory to the new name newname, enter:
mv -i oldname newname
To move a file named hw1 from a subdirectory named newhw to another subdirectory
named oldhw (both subdirectories of the current directory), enter:
mv -i newhw/hw1 oldhw
If, in this last operation, you also wanted to give the file a new name, such as firsthw, you
would enter:
mv -i newhw/hw1 oldhw/firsthw
pwd
This command reports the current directory path. Enter the command by itself:
pwd
rm
This command will remove (destroy) a file. You should enter this command with the -
i option, so that you'll be asked to confirm each file deletion. To remove a file named junk,
enter:
rm -i junk
Note: Using rm will remove a file permanently, so be sure you really want to delete a file
before you use rm.
To remove a non-empty subdirectory, rm accepts the -r option. On most systems this will
prompt you to confirm the removal of each file. This behavior can be prevented by adding
the -f option. To remove an entire subdirectory named oldstuff and all of its contents, enter:
rm -rf oldstuff
Note: Using this command will cause rm to descend into each subdirectory within the
specified subdirectory and remove all files without prompting you. Use this command with
caution, as it is very easy to accidently delete important files. As a precaution, use
the ls command to list the files within the subdirectory you wish to remove. To browse
through a subdirectory named oldstuff, enter:
ls -R oldstuff | less
rmdir
This command will remove a subdirectory. To remove a subdirectory named oldstuff, enter:
rmdir oldstuff
vi
This command starts the vi text editor. To edit a file named myfile in the current directory,
enter:
vi myfile
w and who
The w and who commands are similar programs that list all users logged into the computer.
If you use w, you also get a list of what they are doing. If you use who, you also get the IP
numbers or computer names of the terminals they are using.