Operating Systems
Operating Systems
Operating Systems
M – Scheme
e-TEXTBOOK
on
OPERATING SYSTEMS
for
III Semester COMPUTER ENGINEERING
1. Mrs. P.SARADHA
HOD/COMPUTER ENGG,
GOVERNMENT POLYTECHNIC COLLEGE
KRISHNAGIRI -635 001
3.Mrs.V.BHUVANESWARI
LECTURER /COMPUTER ENGG
GOVERNMENT POLYTECHNIC COLLEGE
DHARMAPURI-635 205
Validated by
Mrs.P.S.NEELAYATHAKSHI
LECTURER(SEL.GRADE)/COMPUTER ENGG
VALIVALAM DESIKAR POLYTECHNIC COLLEGE,
NAGAPATTINAM-611001
UNIT- I
INTRODUCTION TO OPERATING SYSTEMS
OBJECTIVES
o To describe the basic concept of operating system.
o To give an overview of generations of operating system.
o To explore several types of operating systems
o To provide information about major components of operating system
o To describe the various services of operating system .
o To know about the various ways of structuring an operating system.
INTRODUCTION
An operating system is a program that manages a computer’s hardware. It also
provides a basis for application programs and acts as an intermediary between the
computer user and the computer hardware. This unit provides a general overview about
the major components of operating system and its functions . Also gives information about
various services of an operating system provides, how they are provided, how they are
debugged, and about the various methodologies of operating system structures.
1.1.1 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.
Users and processes access the computers resources through the operating system.
The systems of the 1960's were also batch processing systems, but they were able to
take better advantage of the computer's resources by running several jobs at once. So
operating systems designers developed the concept of multiprogramming in which several
jobs are in main memory at once;
For example, on the system with no multiprogramming, when the current job paused to
wait for other I/O operation to complete, the CPU simply sat idle until the I/O finished. The
solution for this problem that evolved was to partition memory into several pieces, with a
different job in each partition. While one job was waiting for I/O to complete, another job
could be using the CPU.
Another major feature in third-generation operating system was the technique called
spooling (simultaneous peripheral operations on line). In spooling, a high-speed device like a
disk interposed between a running program and a low-speed device involved with the
program in input/output.
Another feature present in this generation was time-sharing technique, a variant of
multiprogramming technique, in which each user has an on-line (i.e., directly connected)
terminal. Time-sharing systems were developed to multiprogramming large number of
simultaneous interactive users.
1.1.2.3.1 Multiprogramming
Sharing the processor, when two or more programs reside in memory at the same time, is
referred as multiprogramming. Multiprogramming assumes a single shared processor.
Multiprogramming increases CPU utilization by organizing jobs so that the CPU always has
one to execute.
With the development of LSI (Large Scale Integration) circuits, chips, operating
system entered in the system entered in the personal computer and the workstation age.
Microprocessor technology evolved to the point that it become possible to build desktop
computers as powerful as the mainframes of the 1970s. Two operating systems have
dominated the personal computer scene: MS-DOS, written by Microsoft, Inc. for the IBM PC
and other machines using the Intel 8088 CPU and its successors, and UNIX, which is
dominant on the large personal computers using the Motorola 6899 CPU family.
Desktop Operating SystemA desktop operating system is one that is intended for a
desktop computer (Unless you are a network administrator or something like that, you
probably use a desktop computer.) These OSes usually come with things that one would
probably use at a desk. For example, Windows sometimes comes with Microsoft Office pre-
installed.
The control program in a user's machine (desktop or laptop). Also called a "client
operating system," Windows is the overwhelming majority while the Macintosh
comes second. There are also several versions of Linux for the desktop.
Advantages
1. Increased Throughput.
2. Reduced cost
3. High Reliabilty.
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.
Clustering is the use of multiple computers, typically PCs or UNIX workstations, multiple
storage devices, and redundant interconnections, to form what appears to users as a single
highly available system. Cluster computing can be used for load balancing as well as for
high availability.
Computer cluster technology puts clusters of systems together to provide better system
reliability and performance. Cluster server systems connect a group of servers together in
order to jointly provide processing service for the clients in the network.
Cluster operating systems divide the tasks amongst the available servers. Clusters of
systems or workstations, on the other hand, connect a group of systems together to jointly
share a critically demanding computational task. Theoretically, a cluster operating system
should provide seamless optimization in every case.
At the present time, cluster server and workstation systems are mostly used in High
Availability applications and in scientific applications such as numerical computations
Advantages
1. Reliability is high
2. Portable
3. Load balancing
Sharing the processor, when two or more programs reside in memory at the same time, is
referred as multiprogramming. Multiprogramming assumes a single shared processor.
Multiprogramming increases CPU utilization by organizing jobs so that the CPU always has
one to execute.
The following figure shows the memory layout for a multiprogramming system.
Disadvantages
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.
An embedded operating system is a specialized OS for use in the computers built into
larger systems. An embedded system is a computer that is part of a different kind of m
achine. Examples include computers in cars, traffic lights, digital televisions, ATMs, airplane
controls, point of sale (POS) terminals, digital cameras, GPS navigation systems, elevators,
digital media receivers and smart meters, among many other possibilities.
1.1.3.7.1 Definition
Embedded system is application-oriented special computer system which is scalable on
both software and hardware. It can satisfy the strict requirement of functionality, reliability,
cost, volume, and power consumption of the particular application. With rapid development
of IC design and manufacture, CPUs became cheap. Lots of consumer electronics have
embedded CPU and thus became embedded systems. For example, PDAs, cellphones,
point-of-sale devices, VCRs, industrial robot control, or even your toasters can be embedded
system.
.eCos and TinyOS, are examples of Embedded operating system.
eCos -The Embedded Configurable Operating System (eCos) is an open source, royalty
free real-time OS intended for embedded applications. The system is targeted at
high-performance small embedded systems.
Problem of reliability.
Question of security and integrity of user programs and data.
Problem of data communication.
2. The different locations of memory in the system must be used properly so that each
Operating system loads the instructions into main memory then picks up these
instructions and makes a queue to get CPU time for its execution. The memory manager
tracks the available memory locations which one is available, which is to be allocated or de-
allocated. It also takes decision regarding which pages are required to swap between the
main memory and secondary memory. This activity is referred as virtual memory
management that increases the amount of memory available for each process.
Keep track of which part of memory are currently being used and by whom.
Decide which processes should be loaded into memory when the memory space is
free.
Allocate and de-allocate memory spaces as and when required.
A computer system has several levels of storage such as primary storage, secondary
storage and cache storage. But primary storage and cache storage cannot be used as a
permanent storage because these are volatile memories and its data are lost when power is
turned off Moreover, the main memory is too small to accommodate all data and programs.
So the computer system must provide secondary storage to backup the main memory.
Secondary storage consists of tapes drives, disk drives, and other media.
The secondary storage management provides an easy access to the file and folders
placed on secondary storage using several disk scheduling algorithms.
The four major activities of an operating system in regard to secondary storage
management are:
A file is a collection of related information defined by its creator. Computer can store files
on the disk (secondary storage), which provide long term storage. Some examples of
storage media are magnetic tape, magnetic disk and optical disk. Each of these media has
its own properties like speed, capacity, and data transfer rate and access methods.
A file system is normally organized into directories to make ease of their use. These
directories may contain files and other directories. Every file system is made up of similar
directories and subdirectories. Microsoft separates its directories with a back slash and its
file names aren't case sensitive whereas Unix-derived operating systems (including Linux)
use the forward slash and their file names generally are case sensitive.
The main activities of an operating system in regard to file management are creation and
deletion of files/ folders, support of manipulating files/ folders, mapping of files onto
secondary storage and taking back up of files.
Protection (or security) is the most demanding feature of an operating system. Protection
is an ability to authenticate the users for an illegal access of data as well as system.
Operating system provides various services for data and system security by the means of
passwords, file permissions and data encryption. Generally computers are connected
through a network or Internet link, allowing the users for sharing their files accessing web
sites and transferring their files over the network. For these situations a high level security is
expected.
At the operating system level there are various software firewalls. A firewall is configured
to allow or deny traffic to a service running on top of the operating system. Therefore by
installing the firewall one can work with running the services, such as telnet or ftp, and not to
worry about Internet threats because the firewall would deny all traffic trying to connect to
the service on that port.
If a computer system has multiple users and allows the concurrent execution of multiple
processes, then the various processes must be protected from one another's activities.
Protection refers to mechanism for controlling the access of programs, processes, or users
to the resources defined by a computer system.
An operating system works as a network resource manager when multiple computers are
in a network or in a distributed architecture. A distributed system is a collection of processors
that do not share memory, peripheral devices, or a clock. The processors communicate with
one another through communication lines called network The communication-network
design must consider routing and network strategies, and the problems with network and
security.
Most of today's networks are based on client-server configuration. A client is a program
running on the local machine requesting to a server for the service, whereas a server is a
program running on the remote machine providing service to the clients by responding their
request.
A command interpreter is an interface of the operating system with the user. The user
gives commands which are executed by operating system (usually by turning them into
system calls). The main function of a command interpreter is to get and execute the user
specified command.
Command-Interpreter is usually not a part of the kernel, since multiple command
interpreters may be supported by an operating system, and they do not really need to run in
kernel mode. There are two main advantages of separating the command interpreter from
the kernel.
If you want to change the way the command interpreter looks, i.e., you want to change
the interface of command interpreter, then you can do that if the command interpreter is
separate from the kernel. But if it is not, then you cannot change the code of the kernel and
will not be able to modify the interface.
If the command interpreter is a part of the kernel; it is possible for an unauthenticated
process to gain access to certain part of the kernel. So it is advantageous to have the
command interpreter separate from kernel.
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
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 −
Loads a program into memory.
Executes the program.
Handles program's execution.
Provides a mechanism for process synchronization.
Provides a mechanism for process communication.
Provides a mechanism for deadlock handling.
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 −
1.3.4 COMMUNICATIONS
Operating system performs the communication among various types of processes in the
form of shared memory. In multitasking environment, the processes need to communicate
with each other and to exchange their information. These processes are created under a
hierarchical structure where the main process is known as parent process and the sub
processes are known as child processes.
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 −
Operating system also deals with hardware problems. To avoid hardware problems the
operating system constantly monitors the system for detecting the errors and fixing these
errors (if found). The main function of operating system is to detect the errors like bad
sectors on hard disk, memory overflow and errors related to I/O devices. After detecting the
errors, operating system takes an appropriate action for consistent computing.
This service of error detection and error correction cannot be handled by user programs
because it involves monitoring the entire computing process. These tasks are too critical to
be handed over to the user programs. A user program, if given these privileges; can interfere
with the corresponding operation of the operating systems
In the multitasking environment, when multiple jobs are running at a time, it is the
responsibility of an operating system to allocate the required resources (like as CPU, main
memory, tape drive or secondary storage etc.) to each process for its better utilization. For
this purpose various types of algorithms are implemented such as process scheduling, CPU
scheduling, disk scheduling etc
Following are the major activities of an operating system with respect to resource
management −
1.3.7 ACCOUNTING
Operating system keeps an account of all the resources accessed by each process or
user. In multitasking, accounting enhances the system performance with the allocation of
resources to each process ensuring the satisfaction to each process
end, abort
load, execute
create process, terminate process
get process attributes, set process attributes
wait for time
wait event, signal event
allocate and free memory
Some common system calls are create, delete, read, write, reposition, or close. Also,
there is a need to determine the file attributes – get and set file attribute. Many times the OS
provides an API to make these system calls.
Some system calls exist purely for transferring information between the user program and
the operating system. An example of this is time, or date.
The OS also keeps information about all its processes and provides system calls to report
this information.
get time or date, set time or date
get system data, set system data
get process, file, or device attributes
set process, file, or device attributes
1.3.9.5 Communication
These calls are used to exchange information between different processes running in the
same computer or between different processes running in different systems connected with
each other.
System call is programming interface to the services provided by the OS. It is typically
written in a high-level language such as C or C++.
Step 11: increment stack pointer C program invoking printf() library call, which calls
write() system call.
Fig 1.6 Standard C Library Example
When DOS was originally written its developers had no idea how big and important it
would eventually become. It was written by a few programmers in a relatively short amount
of time, without the benefit of modern software engineering techniques, and then gradually
grew over time to exceed its original expectations. It does not break the system into
subsystems, and has no distinction between user and kernel modes, allowing all programs
direct access to the underlying hardware.
Advantages
1. More modules and extensible
2. Simple construction, debugging, and verification
Disadvantage
The basic idea behind micro kernel is to remove all non-essential services from the
kernel, and implement them as system applications instead, thereby making the
kernel as small and efficient as possible.
Most microkernels provide basic process and memory management, and message
passing between other services, and not much more.
Security and protection can be enhanced, as most services are performed in user
mode, not kernel mode.
System expansion can also be easier, because it only involves adding more system
applications, not rebuilding a new kernel.
Mach was the first and most widely known microkernel, and now forms a major
component of Mac OSX.
Windows NT was originally microkernel, but suffered from performance problems
relative to Windows 95. NT 4.0 improved performance by moving more services into
the kernel, and now XP is back to being more monolithic.
Another microkernel example is QNX, a real-time OS for embedded systems
Advantages
1.Easier to extend
2.Easier to port to new architectures
3.More reliable (less code is running in kernel mode)
4.More secure
Disadvantages
1.No consensus regarding services that should remain in the kernel
2.Performance overhead of user space to kernel space
communication
1.4.6 BOOTING
Booting is a process or set of operations that loads and hence starts the operating
system, starting from the point when user switches on the power button.
Have you ever given it a thought that when you press the power button on your laptop or
PC, what happens behind the logo of Windows XP/Vista/Seven or Linux? From the pressing
of the power button in the computer. there are more than hundred components/peripherals
that are initialized and thousand lines of code is executed during the process of booting.
Boot Sequence As soon as the computer is turned on, the basic input-
output system (BIOS) on your system's read-only memory (ROM) chip is "woken up" and
takes charge.
1. BIOS first does a power-on self test (POST) to make sure all the computer's
components are operational.
2. First, it looks on drive A (unless you've set it up some other way or there is no
diskette drive) at a specific place where operating system boot files are located. If
there is a diskette in drive A but it's not a system disk, BIOS will send you a
message that drive A doesn't contain a system disk. If there is no diskette in
drive A (which is the most common case), BIOS looks for the system files at a
specific place on your hard drive.
3. Having identified the drive where boot files are located, BIOS next looks at the
first sector (a 512-byte area) and copies information from it into specific locations
in RAM. This information is known as the boot record or Master Boot Record.
4. It then loads the boot record into a specific place (hexadecimal address 7C00) in
RAM.
5. The boot record loads the initial system file (for example, for DOS systems,
IO.SYS) into RAM from the diskette or hard disk.
6. The initial file (for example, IO.SYS, which includes a program called SYSINIT)
then loads the rest of the operating system into RAM.
7. The initial file (for example, SYSINIT) loads a system file (for example,
MSDOS.SYS) that knows how to work with the BIOS.
8. One of the first operating system files that is loaded is a system configuration file
(for DOS, it's called CONFIG.SYS). Information in the configuration file tells the
loading program which specific operating system files need to be loaded (for
example, specific device driver.
9. Another special file that is loaded is one that tells which specific applications or
commands the user wants to have included or performed as part of the boot
process. In DOS, this file is named AUTOEXEC.BAT. In Windows, it's called
WIN.INI.
10. After all operating system files have been loaded, the operating system is given
control of the computer and performs requested initial commands and then waits
for the first interactive user input.
In order for a computer to successfully boot, its BIOS, operating system and
hardware components must all be working properly; failure of any one of these three
elements will likely result in a failed boot sequence.
Summary
The operating system provide services to both the users and to the programs.
example-Program execution, i/o operations, file system manipulation,
communication, error detection, resource allocation, protection, system accounting
and system calls.
REVIEW QUESTIONS
PART A (2 Marks)
1. Define operating system.
2. What are the functions of an operating system?
3. Define multiprogramming.
4. List the types of operating system.
5. What are the components available in operating system?
6. List the operating system services.
7. List the different structure of operating system.
PART B (3 Marks)
1. Explain clustered operating system.
2. Explain any one operating system.
3. Explain any one component of operating system.
4. Define system call. List the types of system call.
5. Draw the diagram of Microkernel Architecture.
6. What is Booting?
PART C (5 Marks)
1. Briefly explain the generation of operating system.
2. Explain any two operating systems.
3. Explain any two operating system component.
4. Briefly explain the operating system services
5. Explain the different system calls.
6. Explain system call execution.
7. Explain the concept of virtual machine.
8. Define booting. Explain Booting sequence.
REFERENCES
TEXT BOOK
1. Operating_Systems_Internals_and_Design_Principles_7th_Edition_ William
Stallings(www.ebook-dl.com)
WEB SITES
1. http://www.ittc.ku.edu/~kulkarni/teaching/EECS678/slides/chap2.pdf
2. https://www.google.co.in/search?q=microkernel+os+images&biw=1366&bih=634&noj
=1&
3. http://www.cs.iit.edu/~cs561/cs450/syscalls/steps.html
4. www.tutorialspoint.com/operating_system/os_virtual_memory.htm
UNIT – II
PROCESS MANAGEMENT
OBJECTIVES
Define the term process and explain the relationship between processes and process
control blocks.
Explain the concept of a process state and discuss the state transitions the
processes undergo.
Understand the distinction between process and thread.
Describe the basic design issues for threads.
Explain the difference between user-level threads and kernel-level threads.
Define the term process scheduling
Explain the various scheduling algorithms.
Understand the term IPC and synchronization.
Discuss basic concepts related race conditions and mutual exclusion.
Define and explain semaphores.
List and explain the conditions for deadlock.
Explain the difference between deadlock prevention and deadlock avoidance.
Understand the approaches to deadlock avoidance, deadlock detection and
recovery.
INTRODUCTION
Early computer systems allowed only one program to be executed at a time. This
program had complete control of the system and had access to all the system's resources.
In contrast, current-day computer systems allow multiple programs to be loaded into memory
and executed concurrently. This evolution required firmer control and more
compartmentalization of the various programs. These needs resulted in the notion of a
process/ which is a program in execution. A process is the unit of work in a modern time-
sharing system.
A process includes the process stack, a data section, a heap and text section. The
structure of the process in memory is shown in Figure 2.1.
The text section includes the compiled program code.
The data section contains global variables.
The heap is used for dynamic memory allocation.
The stack is used for local variables, function parameters and return addresses.
Max Stack
Heap
0 Data
Text
When bootstrapping, the kernel manually creates only one process called process 0
or swapper or idle process
The swapper process initializes the kernel data structure, and creates process1.
When no processes are ready to run, the kernel executes the swapper to keep the
CPU occupied.
Process1 also initializes some kernel data structures by invoking the kernel init
function.
There is a parent-child relationship among processes.
The swapper process is the ancestor of all process; it does not have a parent.
Processes created by the same parent are sibling of one another.
When the parent dies, all the siblings become children of the init process. The init
process monitors executions of its children.
All processes in the system are organized into a single tree structure. The root of the
tree is the init process. Each process in the tree is the original parent holds a pointer
to the youngest child.
1. Null New
A new process is created to execute a program.
2. New Ready
The operating system will move a process from the new state to the ready state.
3. Ready Running
When it is time to select a process to run, the operating system chooses one of the
processes in the ready state.
4. Running Terminated
When the process has completed its execution, then it is terminated by the operating
system.
5. Running Ready
When a process’s time quantum expires, then it is taken out from the CPU and
placed back in the ready list.
6. Running Waiting
When a process issues an I/O request, then it is taken out from the CPU and placed
back in the waiting list.
7. Waiting Ready
A process in the waiting state is moved to the ready state, when the event for waiting
is completed.
Figure 2.2 shows the general structure of the process state transition diagram. Each
process may be in one of the following states:
Whenever process changes state, the operating system reacts by placing the
process’s PCB in the list that corresponds to its new state. Only one process can be running
on any processor at any instant and many processes may be ready and waiting state.
2.1.4 PROCESS CONTROL BLOCK
Each process contains the Process Control Block (PCB), which stores the following
process specific information, as illustrated in Figure 2.3.
Process
Pointer
state
Process number
Program counter
CPU registers
Memory limits
List of open files
...
In brief, the PCB simply serves as the repository for any information that may vary
from process to process.
2.1.6 THREADS
A thread is an execution unit consists of a thread ID, a program counter, a
register set and a stack. It shares its code section, data section, and resources with other
threads belonging to the same process. A traditional process has a single thread of control.
If a process has multiple threads of control, it can perform more than one task at a time. A
thread is sometimes called a light weight process. Fig 2.4 shows the single threaded
process.
Stack Register
Thread
Advantages
Thread switching can all be done without the involvement of the kernel
User level threads are fast to create and manage.
Disadvantages
All thread operations are implemented in the kernel and the operating system
schedules all threads in the system. Threads managed by operating system are called
kernel-level threads. The Kernel performs thread creation, scheduling and management in
Kernel space. Kernel threads are generally slower to create and manage than the user
threads.
Advantages
Kernel can simultaneously schedule multiple threads from the same process on
multiple processes.
If one thread in a process is blocked, the Kernel can schedule another thread of the
same process.
Disadvantages
Kernel threads are generally slower to create and manage than the user threads.
Transfer of control from one thread to another within the same process requires a
mode switch to the Kernel.
The method of determining which process in the ready state should be moved to
running state is known as process scheduling. Process scheduling is an essential part of
Multiprogramming operating systems.
In a multiprogramming environment, more than one process resides in main memory
at a time. To maximize CPU utilization, when one process has to wait, the operating system
takes the CPU away from that process and gives the CPU to another process. Scheduling
of this kind is a fundamental operating-system function. Almost all computer resources are
scheduled before use. Since CPU is one of the primary computer resources, its scheduling
is central to the operating system design.
The primary objective of the process scheduling is to keep the CPU busy all the time
in order to maximize the system performance and to deliver minimum response time for all
programs. Some goals that are desirable in all systems are
When more than one process is runnable, the operating system must select one
process for execution. The part of the operating system concerned with this decision is
called the scheduler, and algorithm it uses is called the scheduling algorithm.
There are three types of schedulers available are
Long term scheduler
Short term scheduler
Medium term scheduler
2. Throughput :
It is the total number of processes that are completed per unit time.
3. Turnaround time :
The interval between the time of submission of the process and the time of
completion of the process.
4. Waiting time :
The average period of time a process spent waiting in the ready queue.
5. Response time :
Amount of time it takes from when a request was submitted until the first response is
produced. It is necessary to increase CPU utilization and throughput and to reduce
turnaround time, waiting time, and response time.
CPU scheduling algorithm may use different criteria for selecting which of the
processes in the ready queue is to be allocated the CPU.
Scheduling algorithm may be preemptive or non-preemptive. In preemptive
scheduling, a running process may be replaced by a higher priority process at any time. In
non-preemptive scheduling, once the CPU has been allocated to a process, the process
continues its execution until it terminates or waits for I/O. There are many different CPU-
scheduling algorithms.
Gantt chart is a bar chart that shows a particular schedule, including the start and
finish times of each of the participating processes.
Figure 2.7 shows the Gantt chart of FCFS scheduling, if the processes arrivein the
order p1, p2 & p3.
P1 P2 P3
0 21 27 30
Figure 2.7 Gantt chart
Waiting time:
= 16 milliseconds
In FCFS policy, the average waiting time is not generally minimum. This may vary
substantially if the processes CPU burst times vary greatly. FCFS has relatively low
throughput for heavy workload.
Shortest Job First (SJF) is a scheduling policy that selects the waiting process with
the smallest execution time to execute next. If two processes have the same length, FCFS
scheduling is used to break the tie. SJF algorithm may be either preemptive or non-
preemptive.
A preemptive SJF algorithm will preempt the currently running process, whereas a
non-preemptive SJF algorithm will allow the currently running process to finish its CPU-burst.
Let us consider the set of process with burst time in milliseconds. Arrival time of the
processes is 0 and the processes arrive in the order of p1, p2 and p3
Gantt chart:
P2 P3 P1
0 3 9 30
Waiting time:
= 4 milliseconds
Shortest-Job-First scheduling is an optimal algorithm. It gives the minimum average
waiting time for a given set of processes.
Let us consider the following three processes, with the length of the CPU burst given
in milliseconds
If the processes arrive at the ready queue at the times shown in the above table, then
the resulting preemptive SJF schedule is as depicted in the following Gantt chart
P1 P2 P3 P1
0 1 4 10 30
Process p3 arrives at time 2 with burst time 6ms. The burst time of process p3 is
larger than process p2. So process p2 continues its execution. After the completion
of process p2 process p3 is scheduled since the burst time of process p3 (6
milliseconds) is lesser than process p1.
Finally process p1 is scheduled.
Waiting time:
Waiting time for process p1: The process p1 is scheduled at time 0 and preempted at
time 1. Then it is again scheduled for execution at time10ms. So the waiting time of process
p1 is calculated as follows
Waiting time = (Entry time of next scheduling – Exit time of first scheduling) – Arrival time.
Process p2 and p3 are not preempted during execution. So the waiting time for p2 and p3
are
Waiting time = Entry time of scheduling – Arrival time
Waiting time for p2 = 1 – 1 = 0ms
Waiting time for p3 = 4 – 2 = 2ms
Process Waiting time
P1 9
P2 0
P3 2
Average waiting time:
= 3.67 milliseconds
Let us consider the time quantum of 3 milliseconds. Process P1 gets the first 3
milliseconds. Since it requires another 18 milliseconds, it is preempted after the first time
quantum, and the CPU is given to the next process in the queue, process P2. Process P2 is
preempted after 3 milliseconds.
The CPU is then given to the next process, process P3. Process P3 completes its
execution since its burst time is 3ms. Once each process has received 1 time quantum, the
CPU is returned to process P1 for an additional time quantum. The resulting RR schedule is
as follows:
Gantt chart:
P1 P2 P3 P1 P2 P1 P1 P1 P1 P1
0 3 6 9 12 15 18 21 24 27 30
Waiting Time:
Process P1 = 0 + (9 – 3) + (15 – 12) = 9ms
Process P2 = 3 + (12 – 6) = 9ms
Process P3 = 6ms
Process Waiting time
P1 9
P2 9
P3 6
= 8 milliseconds
2.2.6 MULTIPROCESSOR SCHEDULING
Multiprocessor Operating System refers to the use of two or more central
processing units (CPU) within a single computer system. These multiple CPUs sharing
the computer bus, memory and other peripheral devices. Multiprocessor scheduling refers to
a set of procedures and mechanisms built into the operating system to execute the available
processes by multiple processors.
On a uniprocessor, scheduling is one dimensional. On a multiprocessor, scheduling
is two dimensional. The scheduler has to decide which process to run and which CPU to run
it on.
2.2.7.1 Timesharing
This is the simplest scheduling algorithm for dealing with unrelated processes. The
unrelated processes which are ready to execute are placed in different queues depending
on their priority. Based on the priority, the processes are allocated the available processors.
Figure 2.8 Time sharing scheduling
In figure 2.8, there the 16 CPUs are all currently busy. There are 14 set of prioritized
processes are waiting to run. The first CPU to finish its current work is CPU 4. The highest
priority process A is allocated to CPU4. Next, CPU 12 goes idle and chooses process B.
This scheduling is reasonable as long as the processes are completely unrelated.
This multiprocessor scheduling can be used when processes are related to one
another. A single process creates multiple threads that work together. Scheduling multiple
threads at the same time across multiple CPUs is called space sharing.
The computer system is described as a network of servers. Each server has a queue
of waiting processes. The CPU is a server with its ready queue, as is the I/O system with its
device queues. Knowing arrival rates and service rates, we can compute utilization, average
queue length, average wait time, and so on. This area of study is called queueing-network
analysis.
As an example, let η be the average queue length, let W be the average waiting time
in the queue, and let λ be the average arrival rate for new processes in the queue. We
expect that during the time W that a process waits, λ x W new processes will arrive in the
queue.
If the system is in a steady state, then the number of processes leaving the queue
must be equal to the number of processes that arrive. Thus,
η = λ x W.
Queueing analysis can be useful in comparing scheduling algorithms, but it has some
limitations.
2.2.7.3 SIMULATION
Let us assume that the bounded buffer is used as shared memory. The shared buffer
is implemented as a circular array with two pointers: in and out.
#define BUFFER_SIZE 10
int in = 0;
int out = 0;
int count = 0;
int buffer[BUFFER_SIZE];
Producer process
Void Producer()
{
int item;
while (true)
{
item = produceitem();
if(count == BUFFER_SIZE); /* do nothing */
buffer[in] = item;
in = (in + 1) % BUFFER_SIZE;
count++;
}
Consumer process
Void consumer()
(
Int item;
while (true) {
if(count == 0); /* do nothing */
item = buffer[out];
out = (out + 1) % BUFFER_SIZE;
count--;
}
From the above example, it is clear the both the producer process and the consumer
process attempt to access the shared buffer concurrently.
Example: Chat program allows the participants to communicate each other by exchanging
the messages.
Process A Process B
while (TRUE) { while (TRUE) {
produce an item receive(A,item)
send (B, item) consume-item
} }
Links are established automatically between each pair of processes that wants to
communicate.
A link is associated with exactly one pair of communicating processes.
Between each pair there exists exactly one link.
The link may be unidirectional or bi-directional.
Exit section
Remainder section
}
The critical sections should satisfy the following requirements.
1. Mutual exclusion: Only one process can be in the critical section at a time. i.e., If one
process is executing in its critical section, then other processes are not allowed to execute
their critical section.
2. Progress: If no process is executing in its critical section then only those processes that
are not executing in their remainder sections will enter its critical section next.
3. Bounded waiting: After a process made a request to enter its critical section and beforeit
is granted the permission to enter, there exists a bound on the number of times that other
processes are allowed to enter.
We consider only two processes that interchange execution between their critical
sections and remainder sections. Both processes share the common integer variable.
Let us consider the name of the processes is p0 and p1, the name of the variable is
turn and flag. If flag [0] is true then process P0is ready to enter its critical section. The
variable turn indicates whose turn it is to enter its critical section. That is, if turn == 0, then
process P0 is allowed to execute in its critical section.
do
{
flag[0]=true;
turn = 1;
while(flag(1) && turn==1);
critical section
flag[0]=false;
} while(true)
To enter the critical section, process P0 first sets flag [0] to be true and then sets turn
to the value. Then it checks the condition. Since the condition is false, process p0 performs
no-operation at entry section. It enters its critical section. Once it completes its execution, it
sets the flag value as false. The same procedure used by process p1 to executes its critical
section. From the example the mutual exclusion is preserved.
2.3.6 SEMAPHORES
Semaphore is a hardware based solution used to solve critical section problem. A
Semaphore is indicated by an integer variable S. Semaphore variable is accessed through
two operations wait() and signal().
1. Wait: It is used to test the semaphore variable. It decrement the semaphore value. If the
value become negative, then the execution of wait() operation is blocked.
2. Signal: It increment the semaphore value.
Entry to the critical section is controlled by wait operation and exit from a critical
section is taken care by signal operation. The wait and signal operation are also called P and
V operations. If number of processes attempts the wait operation, only one process will be
allowed to proceed. Thus mutual exclusion is enforced
Pseudo code for wait
Wait(S)
{
While(S<=0) do no-op;
S=S-1;
}
2.4.1 DEFINITION
In a multiprogramming environment, several processes may compete for a finite
number of resources. A process requests resources; if the resources are not available at that
time, the process enters a waiting state. Sometimes, a waiting process is never again able to
change state, because the resources it has requested are held by other waiting processes.
This situation is called a deadlock.
Deadlocks are a set of blocked processes each holding a resource and waiting to
acquire a resource held by another process.
Figure 2.11 Traffic gridlock is a real time example for deadlock situation
A process must request a resource before using it and must release the resource
after using it. A process may request as many resources as it requires for completing its
task. Obviously, the number of resources requested may not exceed the total number of
resources available in the system.
Under the normal mode of operation, a process may utilize a resource in only the
following sequence:
Request. The process requests the resource. If the request cannot be granted
immediately, then the requesting process must wait until it can acquire the resource.
Use. The process can use resource.
Release. Release the resource.
3. No preemption.
Resources cannot be preempted; that is, a resource can be released only voluntarily
by the process holding it, after that process has completed its task.
4. Circular wait.
A set {P0, P1 … Pn} of waiting processes must exist such that P0is waiting for a
resource held by P1, P1 is waiting for a resource held by P2, ... , Pn-1 is waiting for a
resource held by Pn, and Pn is waiting for a resource held by P0.
To ensure that the hold-and-wait condition never occurs in the system, we must
guarantee that, whenever a process requests a resource, it does not hold any other
resources.
One way used is each process must collect all the resources before it begins
execution. Another way allows a process to request resources only when it has none. A
process may request some resources and use them. Before it can request any additional
resources, however, it must release all the resources that it is currently allocated.
Both these methods have two main disadvantages.
1. Resource utilization may be low, since resources may be allocated but unused for a
long period.
2. Starvation is possible. A process that needs several popular resources may have to
wait indefinitely.
3. No preemption
If a process is holding some resources and requests another resource that cannot be
immediately allocated to it then all resources the process is currently holding are preempted.
The preempted resources are added to the list of resources for which the process is waiting.
The process will be restarted only when it can regain its old resources in addition with the
new ones that it is requesting.
4. Circular wait
One way to prevent the circular wait condition is by linear ordering of different types
of resources. In this, the resources are divided into different classes. The following rules are
used to prevent the possibility of circular wait.
A safe state is a state in which the system can allocate resources to each process in
some order and still avoid a deadlock. A sequence of processes <P1, P2, ... , Pn>is a safe
sequence for the current allocation state if, for each Pi, the resource requests that Pi can still
make can be satisfied by the currently available resources plus the resources held by all Pj,
with j <i.
A safe state is not a deadlocked state. An unsafe state may lead to a deadlock. As
long as the state is safe, the operating system can avoid deadlocked. In an unsafe state, the
operating system cannot prevent processes from requesting resources in such a way that a
deadlock occurs.
Let us we consider a system with 12 magnetic tape drives and 3 processes namely
P0, P1and P2. The maximum needs, number of resources allocated and the current needs
of each process are given in the table.
At time t0, the system is in a safe state. The sequence <P1, P0, P2> satisfies the
safety condition. Process P1 can immediately be allocated all its tape drives and then return
them, then process Po can get all its tape drives and return them and finally process P2 can
get all its tape drives and return them. The safe sequence is shown in the following table.
No. of resources
Max Initially Currently returned by Total
Process Available
Needs Allocated allocated processes after available
execution
P1 4 2 2 1 4 5
P0 10 5 5 0 10 10
P2 9 2 7 3 9 12
If we have only one instance of each resource type, then resource allocation graph is
used for deadlock avoidance. The resource allocation graph normally contains the request
and assignment edges. In addition to that, a new type of edge, called a claim edge is added.
A claim edge Pi Rj indicates that process Pi may request resource Rj at some time in the
future. The claim edge is shown by dotted lines. Figure 2.14 shows the deadlock avoidance
with resource allocation graph.
When process Pi requests resource Rj, the claim edge Pi Rj is converted to a
request edge. Similarly, when a resource Rj is released by Pi the assignment edge Rj Pi is
reconverted to a claim edge Pi Rj.
Cycle detection algorithm is used for detecting cycle in the graph. If no cycle exists,
then the allocation of the resource will leave the system in a safe state. If a cycle is found,
then the allocation will put the system in an unsafe state.
Safety algorithm is used to find whether or not a system is in a safe state. This
algorithm can be described as follows
1. Let Work and Finish be vectors of length m and n, respectively. InitializeWork=
Available and Finish[i] =false for i = 0, 1, ... ,n - 1.
2. Find an I such that both
a. Finish[i] ==false
b. Needi<= Work
If no such i exists, go to step 4.
3. Work = Work + Allocationi
Finish[i] = true
Go to step 2.
4. 4If Finish[i] ==true for all i, then the system is in a safe state
If all resources have only a single instance, then a wait-for graph is used to detect the
deadlock.
An edge from Pi to Pj in a wait-for graph implies that process Pi is waiting for process
Pj to release a resource that Pi needs. An edge PiPj exists in a wait-for graph if and only if
the corresponding resource allocation graph contains two edges PiRq and RqPj for some
resource Rq.
Figure 2.15 Resource allocation graph with corresponding wait for graph
If the wait-for graph contains a cycle, then there is a deadlock. To detect deadlocks,
the system needs to maintain the wait-for graph and periodically invoke an algorithm that
searches for a cycle in the graph.
1. Let Work and Finish be vectors of length m and n, respectively. Initialize Work=
Available. For i= 0, 1, ... ,n-1, if Allocationi <>0, then Finish[i] =false; otherwise,
Finish[i] = true.
4. If Finish[i] ==false for some i, 0<= i <n, then the system is in a deadlocked state.
Moreover, if Finish[i] ==false, then process Pi is deadlocked.
Summary
Process is an instance of program running on computer.
In Operating system, system processes and user processes are the major
categories of process.
The process has different states-New, Ready, Running, Waiting and Terminated
states.
The thread is a dispatchable unit of work within the process
The major difference between process and thread are
S.No Process Thread
1. Process is heavy weight Thread is light weight
Process switching needs interaction Thread switching does not need to
2. with operating system. interact with operating system
In multiple processing environments, All threads can share same set of open
each process executes the same code files, child processes.
3.
but has its own memory and file
resources.
If one process is blocked, then no While one thread is blocked and
4. other process can execute until the first waiting, a second thread in the same
process is unblocked. task can run.
The different types of threads are user level and kernel level threads
Process scheduling is the method of determining which process in the ready state
should be moved to running state.
There are three types of schedulers-Long term,Short term and medium term
Different scheduling algorithms are present which are following the criteria--- CPU
utilisation, throughput, turnaround time, waiting time and response time
The scheduling algorithms are first come first served, shortest job first scheduling,
round robin scheduling, multiprocessor scheduling and gang scheduling.
The algorithms are evaluated by the following method--Deterministic model,
Queueing model and simulation
Inter process communication is a mechanism that allows the exchange of data
between processes the two models are shared memory and message passing
Race condition is a situation where more than one processes access and manipulate
shared data at a time then the result of the execution depends on the order in which
the access takes place.
Mutual exclusive is only one process can be in the critical section at a time, i.e if one
process is executing in its critical section then other processes are not allowed to
execute their critical section.
Semaphore is a hardware based solution used to solve critical section problem.
Deadlock is a situation if a waiting process is never again able to change state
because the resources it has requested are held by other waiting processes.
Deadlocks can be prevented by preventing at least one of the four required
conditions-Mutual Exclusion, hold and wait, No pre-emption and circular wait.
Deadlock avoidance can be done by safe state, Resource allocation graph, bankers
Algorithm.
Deadlock Detection algorithm is done by operating system periodically – there are
two types of algorithm –single instance of each resource type ,several instances of
resource type
Deadlock recovery is done by process termination and resource pre-emption.
REVIEW QUESTIONS
PART - A
1. Define Process.
2. What is process control block?
3. List the states of the process.
4. Draw the structure of PCB.
5. Define context switching.
6. What is thread?
7. List the types of threads.
8. Write any two advantages of threads.
9. Define Throughput.
10. Define Turnaround time.
11. What is the objective of scheduling?
12. List the types of scheduler.
13. Define CPU scheduler.
14. Define swapping.
15. What do you mean by preemptive and non-preemptive scheduling?
16. What is multiprocessor scheduling?
17. When gang scheduling is used?
18. Define race condition.
19. Define critical section.
20. What is semaphore?
21. Define deadlock.
22. List the characteristics of deadlock.
23. What is mutual exclusion
24. What is a resource allocation graph?
25. What is a wait for graph?
PART – B
1. What are the benefits of threads?
2. Write short notes on user level threads.
3. Write brief notes on the concept of multithreading.
4. Differentiate process and threads.
5. Write any three scheduling criteria.
6. What is space scheduling?
7. Explain the following transition between process states
a. Running Ready
b. Running Terminated
c. Running Waiting
8. Briefly write about semaphore.
9. Write about deadlock recovery.
PART – C
1. Explain process state transition with neat diagram.
2. With neat sketch, write briefly about PCB.
3. Explain the types of threads.
4. Describe the various types of schedulers.
5. Explain FCFS scheduling algorithm with an example.
6. Explain non-preemptive SJF scheduling algorithm with an example.
7. Explain preemptive SJF scheduling algorithm with an example.
8. Explain round robin scheduling algorithm with an example.
9. Explain various types of multiprocessor scheduling.
10. Explain the various method for evaluating the performance of the
scheduling algorithm
11. What is shared memory? Explain it with an example
12. Explain various message passing techniques.
13. Explain critical section in detail.
14. Describe the characteristics of deadlock.
15. What are the methods to prevent a deadlock? Explain
16. Explain how safe state is used to avoid deadlock with an example
17. Explain any one deadlock avoidance strategy.
18. Write the deadlock detection algorithm for several instances of
resource system.
UNIT – III
MEMORY MANAGEMENT
OBJECTIVES
After studying this unit, the student should be able to:
Provide a detailed description of various ways of organizing memory hardware.
Understand the reason for memory partitioning and explain the various types that are
used.
Understand and explain the concept of fragmentation and its types.
Understand and explain the concept of paging its advantages .
Summarize key security issues related to memory management.
Define virtual memory.
Describe the hardware and control structures that support virtual memory.
Describe the benefits of a virtual memory system.
Explain the concepts of demand paging, page-replacement algorithms.
Introduction:
Memory is a valuable system resource which must be carefully managed and shared
between programs and processes . Also it should be protected against access by other
programs.
Memory management is the process of managing the computer memory which consist of
primary memory or secondary memory. In this, we allocate the memory portions to programs
and softwares after freeing the space of the computer memory. Basically, memory
management is of critical importance for operating system because the multi-tasking can
take place in the system which switches the memory space from one process to another.
Moreover, the concept of the virtual memory is used in the system according to which
programs from main memory are loaded to the secondary memory when the space is not
large enough to hold the programs.
Memory management keeps track of each and every memory location, regardless of
either it is allocated to some process or it is free. It checks how much memory is to be
allocated to processes. It tracks whenever some memory gets freed or unallocated and
correspondingly it updates the status.
The main functions of memory management are:
Keeps track of the status of each memory location, either allocated or free.
Determines how memory is allocated among processes.
Decides which process will get memory at what time .
Determines which memory locations will be assigned.
Keeps track of when memory is freed or unallocated and updates the status.
Physical address actual memory address which denotes a memory area in the
storage device is the one that is loaded into the memory address register of the memory.
Physical memory may be mapped to different logical addresses for various purposes.
The process of converting logical (virtual) address into physical address at run time
is called memory mapping. This run-time mapping is done by a hardware device called the
memory-management unit (MMU).
The MMU has two special registers that are accessed by the CPU’s control unit. A data to be
sent to main memory or retrieved from memory is stored in the Memory Data
Register (MDR). The desired logical memory address is stored in the Memory Address
Register (MAR). The address translation is also called address binding and uses a memory
map that is programmed by the operating system. Before memory addresses are loaded on
to the system bus, they are translated to physical addresses by the MMU.
The set of all logical addresses (generated by a program) is referred to as Logical address
space. The set of all Physical addresses corresponding to these logical addresses is
referred to as physical address space.
For example, P2 is a user program, with size 256 KB. But program is loaded in the main
memory from 13000 to 13256 KB; this address is called physical address. The user program
deals with logical addresses.
The value in the relocation register is added to every address generated by a user process
and it is then sent to memory. Mapping is done as follows:
Physical address space = Logical address space + relocation register value
ie., 13256 = 256 + 13000
Contiguous memory allocation is a method that assigns a user process in memory blocks
having consecutive addresses.
The main memory is usually divided into two partitions: one for the resident operating system
and one for the user processes.
Low Memory − Operating system resides in this memory.
High Memory − User processes are held in high memory.
Advantages
It is simple.
It is easy to understand and use.
Disadvantages
It leads to poor utilization of processor and memory.
User process is limited to the size of available memory
3.1.3.2.1FixedpartitionAllocation
One of the simplest methods for allocating memory is to divide memory into several
fixed sized, non overlapping partitions. This method divides the main memory into equal
number of fixed sized partitions, operating system occupies some fixed portion and
remaining portion of main memory is available for user processes. Any process whose size
is less than or equal to a partition size can be loaded into the partition. If all partitions are
occupied, the operating system can swap a process out of a partition. If a program is too
large to fit in a partition, then the programmer must redesign the program .
In this method, the main memory use is inefficient. Any program, no matter how
small, occupies an entire partition. The left over space in partition, after program
assignment, is called internal fragmentation.Unequal-size partitions will decrease these
problems. Equal-size partitions was used in early IBMs OS/MFT (Multiprogramming with a
Fixed number of Tasks)
Fig 3.5 Fixed Partition - Example
Advantages
1. Any process whose size is less than or equal to the partition size can be loaded
into any available partition.
2 . It supports multiprogramming.
Disadvantages
1.If a program is too big to fit into a partition use overlay technique.
2, Memory use is inefficient, i.e., block of data loaded into memory may be
smaller than the partition. It is known as internal fragmentation.
3.1.3.2.2 Variable Size Partitions
In this type of allocation, main memory is divided into a number of fixed-sized
partitions where each partition should contain only one process. When a partition is free, a
process is selected from the input queue and is loaded into the free partition. When the
process terminates, the partition becomes available for another process.
Each partition may contain exactly one process. In this multiple-partition
method, 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. The operating system keeps a table indicating which parts of memory are
available and which are occupied. Finally, when a process arrives and needs memory, a
memory section large enough for this process is provided.
Fragmentation occurs in memory allocation system when many of the free blocks
are too small to satisfy any request.
As processes are loaded and removed from memory, the free memory space is broken into
little pieces. It happens after sometimes that processes cannot be allocated to memory
blocks considering their small size and memory blocks remains unused. This problem is
known as Fragmentation.
Fragmentation is of two types: 1. Internal fragmentation
2. External fragmentation
Internal Fragmentation:
Internal fragmentation is the space wasted inside of allocated memory blocks
because of restriction on the allowed sizes of allocated blocks. Allocated memory may be
slightly larger than requested memory; this size difference is memory internal to a partition,
but not being used. Internal fragmentation occurs when memory allocation is based on fixed-
size partitions where after a small size application is assigned to a slot and the remaining
free space of that slot is wasted. Internal fragmentation occurs when more storage is
allocated than is actually requested. This left over space, known as slack space, causes a
degradation of system performance
Fig 3.7 Internal Fragmentation
Main Memory
We have 285 k memory available, but we can not fix p6 process, due to Internal
fragmentation.
External Fragmentation:
Main Memory
We have 560k of available memory but we cannot fix P5 process, due to External
fragmentation.
This can be reduced using External This can be solved using compaction where
Fragmentation. However this solution suffer all the empty spaces are combined together.
from external fragmentation.
.
Fig 3.9 showing the difference between Internal and External Fragmentation
3.1.4.2 Compaction:
Memory compaction is the process of moving allocated objects together, and
leaving empty space together. Swapping creates multiple fragments in the memory
because of the processes moving in and out. Memory compaction refers to combining all the
empty spaces together and then combining all the processes together. The disadvantage of
memory compaction is that it requires too much of CPU time.
The following diagram shows how fragmentation can cause waste of memory and a
compaction technique can be used to create more free memory out of fragmented memory
A computer can address more memory than the amount physically installed on the system.
This extra memory is actually called virtual memory.
Similarly, main memory is divided into small fixed-sized blocks of (physical) memory called
frames (size is power of 2, between 512 bytes and 8192 bytes). and the size of a frame
is kept the same as that of a page to have optimum utilization of the main memory and to
avoid external fragmentation
3.1.6.2 Address Translation
Page address is called logical address and represented by page number and the offset.
Frame address is called physical address and represented by a frame number and the
offset.
A data structure called page map table is used to keep track of the relation between a page
of a process to a frame in physical memory.
When a process is to be executed, its corresponding pages are loaded into any available
memory frames. Suppose you have a program of 8Kb but your memory can accommodate
only 5Kb at a given point in time, then the paging concept will come into picture. When a
computer runs out of RAM, the operating system (OS) will move idle or unwanted pages of
memory to secondary memory to free up RAM for other processes and brings them back
when needed by the program.
This process continues during the whole execution of the program where the OS keeps
removing idle pages from the main memory and write them onto the secondary memory and
bring them back when required by the program.
Page address is called logical address and represented by page number and the offset.
A data structure called page map table is used to keep track of the relation between a page
of a process to a frame in physical memory.
Paging Example 1:
The page size (like the frame size) is defined by the hardware. The size of a page is typically
a power of 2, varying between 512 bytes and 16 MB per page, depending on the computer
architecture. The selection of a power of 2 as a page size makes the translation of a logical
address into a page number and page offset particularly easy. If the size of logical address
space is 2m and a page size is 2n addressing units (bytes or words), then the high-order m –
n bits of a logical address designate the page number, and the n low-order bits designate the
page offset.
1. Page number (p) – used as an index into a page table which contains base
address of each page in physical memory.
2. Page offset (d) – combined with base address to define the physical
memory address that is sent to the memory unit.
where p is an index into the page table and d is the displacement within the page.
Fig 3.13 Logical address
Paging Example 2:
Assume a page size of 1K and a 15-bit logical address space. Given : Size of logical
address = 2 ^ 15 = 32788 ( m=15)
No. of bits required to address each byte within a 1024-byte page = 10 bits (n=10, 2^10 =
1024).
Given : Size of logical address = 2 ^ 15 = 32788 so, m=15 & n = 10
Assuming a 15-bit address space with 8 logical pages. How large are the pages?
Answer: 2^12 = 4K. It takes 3 bits to reference 8 logical pages (2^3 = 8).
This leaves 12 bits for the page size and thus pages are 2^12.
Consider logical address 2049 and the following page table for some process P0.
Assume a 15-bit address space with a page size of 1K.
What is the physical address to which logical address 2049 will be mapped?
Solution :
Logical Pages
Since there are 5-bits allocated to the logical page, the address is broken up as follows:
00010 0000000001
Logical page number offset within page
Step 3. Use logical page number as an index into the page table to get physical page
number.
Logical Address:
00010 0000000001
Logical Address
00010 0000000001
00010
00011 0000000001
Step 5:
Logical address Physical address
0 0
1 1024
24
2 2048
3 3072
4 4096
000110000000001 = 3073
Logical address 2049 is mapped to --------------- > physical address 3073
i) Page table
ii) Translation look-aside buffers (TLB)
iii) Page table is kept in main memory.
iv) Page-table base register (PTBR) points to the page table.
v) Page-table length register (PRLR) indicates size of the page table.
The diagram below shows the Hardware support for Paging Hardware With TLB.
Fig 3.14 Paging using TLB
In this scheme every data/instruction access requires two memory accesses. One for the
page table and one for the data/instruction. The two memory access problem can be solved
by the use of a special fast-lookup hardware cache called associative memory or translation
look-aside buffers (TLBs)
Working:
If the page number is not in the TLB (TLB miss) a memory reference to the
page table must be made.
In addition, we add the page number and frame number into TLB
If the TLB already full, the OS have to must select one for replacement
Some TLBs allow entries to be wire down, meaning that they cannot be
removed from the TLB, for example kernel codes
The percentage of times that a particular page number is found in the TLN is
called hit ratio
If it takes 20 nanosecond to search the TLB and 100 nanosecond to access
memory
If our hit ratio is 80%, the effective memory access time equal to:
0.8*(100+20) + 0.2 *(100+100)=140
If our hit ratio is 98%, the effective memory access time equal:
0.98*(100+20) + 0.02 *(100+100)=122
3.1.6.4 Protection and sharing
1. “valid -v” indicates that the associated page is in the process’ logical address
space, and is thus a legal page.
2. “invalid – i ” indicates that the page is not in the process’ logical address
space.
3. Sharing code and data takes place if two page table entries in different processes
point to same physical page, the processes share the memory. If one process writes the
data, other process will see the changes. It is a very efficient way to communicate.
4. Sharing must also be controlled to protect modification and accessing data in one
process by another process. Programs using procedures and data that are non-
modifiable can be shared.
Advantages
Disadvantages
A computer can address more memory than the amount physically installed
on the system. This extra memory is actually called virtual memory and it is a section of a
hard disk that's set up to emulate the computer's RAM. Virtual memory is a memory
management capability of an OS that uses hardware and software to allow a computer to
compensate for physical memory shortages by temporarily transferring data from random
access memory (RAM) to disk storage. Virtual Memory is a space where large programs
can store themselves in form of pages while their execution and only the required pages or
portions of processes are loaded into the main memory. Thus we can have large virtual
memory on a small physical memory.
1. Programs can be larger than physical memory since virtual memory allows us to
extend the use of physical memory by using disk.
2. It allows us to have memory protection, because each virtual address is translated to
a physical address.
3. Less I/O required, leads to faster and easy swapping of processes.
4. Higher degree of multiprogramming is possible since only portions of programs are in
memory
The O.S keeps more often used data in main memory, and everything else in
secondary memory. Because of the principle of Locality of Reference, we can be sure
that most memory references will be to locations already stored in main memory,
thereby improving efficiency and providing a flat memory model. This scheme is used in
modern operating systems and is called virtual memory. Virtual memory gives users the
appearance of unlimited primary memory by transparently utilizing secondary memory.
4. Page Table : Each running program, plus the data structures needed to manage
it, is called a process. For every active process, the O.S assigns a page table.
This table is used for recording the information about the page frames allocation to
the various pages brought in from the hard disk. and is used by a virtual memory
system map between physical frames and virtual pages. Each page table entry
contains information about a single page. The most important part of this
information is a frame number — where the page is located in physical memory.
A page table consists of :
Page no : Number of the page brought in from the hard disk.
Frame no.: Number of the page frame allotted from the main memory.
Valid bit (v): A valid bit (v) tells if the page is currently in main memory or if it
must be retrieved from virtual memory. If the page is in main
memory v is set to 1. When a page is taken from disc and put back
into main memory, v is set to 0 and then it indicates a page fault.
Dirty Bit or Modified Bit (m) : . A Dirty or modifed bit (m) tells if a page has
been written to while in main memory. If it hasn't been modified, m
is set to 1. If it hasn't been modified, and a copy of it is in virtual
memory, it doesn't need to be written to disc,hence the system
speeds up. If it has modified, m is set to 0 and the page must be
written to virtual memory.
5. Working set : This is the set of pages of the program which are currently active
in the main memory. A process will never be executed unless its working set is
resident in main memory. Pages outside the working set may be discarded at any
time. The working set contains only pageable memory allocations; When a
process references pageable memory that is not currently in its working set, a
page fault occurs. The system page fault handler attempts to resolve the page
fault and, if it succeeds, the page is added to the working set.
An invalid page fault or page fault error occurs when the operating system cannot find the
data in virtual memory. This usually happens when the virtual memory area, or the table that
maps virtual addresses to real addresses, becomes corrupt.
Principle of Working of Virtual Memory : Address Translation
using Paging:
When the page is needed, the operating system copies it from disk to main memory,
translating the virtual addresses into real addresses. The process of translating virtual
addresses into real addresses is called mapping. The copying of virtual pages from disk to
main memory is known as paging or swapping.
Virtual memory address translation uses page tables. These are simple arrays in memory
indexed by page number. Address translation combines the frame number with the offset
part of a logical address to form a physical address.The addresses that appear in programs
are the virtual addresses or program addresses. For every memory access, either to fetch
an instruction or data, the CPU must translate the virtual address to a real physical address.
A virtual memory address can be considered to be composed of two parts: a page number
and an offset into the page. The page number determines which page contains the
information and the offset specifies which byte within the page. The size of the offset field is
the log base 2 of the size of a page.
16MB Maximum Virtual Address space (24 bits) ; 8MB Maximum Physical Address space
(23 bits) ; 1024byte Page size (10 bits)
13 bits 10 bits
To convert a virtual address into a physical address, the CPU uses the page number as an
index into the page table. If the page is resident, the physical frame address in the page
table is concatenated in front of the offset to create the physical address.
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
Disadvantages
Number of tables and the amount of processor overhead for handling page interrupts
are greater than in the case of the simple paged management techniques.
Paging happens whenever a page fault occurs and a free page cannot be used for allocation
purpose accounting to reason that pages are not available or the number of free pages is
lower than required pages.
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.
A page replacement algorithm looks at the limited information about accessing the pages
provided by hardware, and tries to select which pages should be replaced to minimize the
total number of page misses, while balancing it with the costs of primary storage and
processor time of the algorithm itself. There are many different page replacement algorithms.
We evaluate an algorithm by running it on a particular string of memory reference and
computing the number of page faults,
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
Oldest page in main memory is the one which will be selected for replacement.
Easy to implement, keep a list, replace pages from the tail and add new pages at the
head.
This algorithm requires that each page have two additional status bits 'R' and
'M' called reference bit and change bit respectively. The reference bit(R) is automatically
set to 1 whenever the page is referenced. The change bit (M) is set to 1 whenever the
page is modified. These bits are stored in the PMT and are updated on every memory
reference. When a page fault occurs, the memory manager inspects all the pages and
divides them into 4 classes based on R and M bits.
Class 1: (0,0) − neither recently used nor modified - the best page to replace.
Class 2: (0,1) − not recently used but modified - the page will need to be written out
before replacement.
Class 3: (1,0) − recently used but clean - probably will be used again soon.
Class 4: (1,1) − recently used and modified - probably will be used again, and write
out will be needed before replacing it.
This algorithm removes a page at random from the lowest numbered non-empty class. The
main attraction of NRU is that it is easy to understand, moderately efficient to implement.
3.2.4.4 The Second Chance Page Replacement
The Second Chance replacement policy is called the Clock replacement policy...
In the Second Chance page replacement policy, the pages for removal are consider
in a round robin matter, and a page that has been accessed between consecutive
considerations will not be replaced.
Implementation:
o Add a "second chance" bit to each memory frame.
o Each time a memory frame is referenced, set the "second chance" bit to ONE
(1) - this will give the frame a second chance...
o A new page read into a memory frame has the second chance bit set to
ZERO (0)
o When you need to find a page for removal, look in a round robin manner in
the memory frames:
If the second chance bit is ONE, reset its second chance bit (to
ZERO) and continue.
If the second chance bit is ZERO, replace the page in that memory
frame.
The following figure shows the behaviour of the program in paging using the Second
Chance page replacement policy:
Page which has not been used for the longest time in main memory is the one which
will be selected for replacement.
Easy to implement, keep a list, replace pages by looking back into time.
This algorithm suffers from the situation in which a page is used heavily during the
initial phase of a process, but then is never used again.
Summary
REVIEW QUESTIONS
PART A (2 Marks)
1. What are the main tasks of Memory management.
2. List the two types of memory available in a computer system.
3. Define : Physical address.
4. Define : Logical address.
5. What are the features of Main memory?
6. What is a secondary memory?
7. What is the use of memory mapping hardware?
8. What do you mean by memory allocation?
9. What is Internal fragmentation?
10. what is External fragmentation?
11. What is Memory compaction?
12. What is Paging?
13. Define address translation?
14. What is protection?
15. Define Virtual memory?
16. What is Demand paging?
17. What is the use of dirty bit?
18. What is Working set?
19. Define Page fault.
20. What is Page replacement?
PART B (3 Marks)
1. Explain Logical and physical address mapping.
2. Draw the structure of contiguous memory allocation.
3. Give the merits and demerits of variable partitioned allocation in memory.
4. What is basic concept of paging?
5. What are the components of page map table?
6. List the advantages of paging.
7. What is memory sharing?
8. Give the concept of page replacement policy?
PART C (5 Marks)
1. Briefly explain the logical and physical address map .
2. Explain fixed and variable partitioned allocation.
3. Discuss Internal and External fragmentation with example.
4. With diagram , explain the concept of compaction.
5. Discuss with example , the principle of paging.
6. Discuss various protection and sharing mechanisms.
7. Explain the hardware needed in paging with diagram.
8. Discuss the basic concept of Demand paging with diagram.
9. Write notes on : page frame, page fault, working set and dirty bit.
10. Explain any two page replacement policy.
UNIT IV
I/O AND FILE MANAGEMENT, SECURITY & PROTECTION
Objectives:
Understand the structure and performance of disk drives.
Discuss about Disk scheduling and its various algorithms.
Explain the concept of RAID and describe the various levels.
Describe the basic concepts of files and file systems.
Study Directory structures.
Understand the principal techniques for file organization and access methods.
Define Disk formatting.
To explore file-system security and protection through various mechasisms.
Introduction
Computers operate a great many kinds of I/O devices. General categories are
storage devices (disks, tapes), transmission devices (network cards, modems), and human-
interface devices (screen, keyboard, mouse). I/O management deals with the control of I/O
devices connected to the computer and this is a major concern of operating-system since
I/O devices vary so widely in their function and speed .
The most important form of I/O is the Magnetic disk I/O. Since there is a vast difference in
speed between the Disks and processor/main memory which slows down the performance,
disk management enforce various disk scheduling policies to improve it.
In most applications, the file is the central element. And the input to the application is by
means of a file; but in all applications, output is saved in a file for long term storage which is
later accessed by the user and programs. The file system permits users to create data
collections, called files and access files through the file management system. The main
objective for a file management system is to meet the data management needs and
requirements of the user, which include storage of data and the ability to perform the various
file operations.
Protection mechanisms control access to a system by limiting the types of file access
permitted to users. Protection ensure that only authorised processes can operate on
memory segments, the CPU, and other resources.
Security ensures the authentication of system users to protect the integrity of the information
stored in the system (both data and code), as well as the physical resources of the computer
system.The security system prevents unauthorized access, malicious destruction or
alteration of data.
Disks provide the bulk of secondary storage for modern computer systems. Magnetic
tape was used as an early secondary storage medium, but the access time is much
slower than for disks.
Modern disk drives are addressed as large one dimensional arrays of logical blocks,
where the logical block is the smallest unit of transfer. The size of a logical block is
usually 512 bytes, although some disks can be low level formatted to choose a
different logical block size, such as 1024 bytes. The one dimensional array of logical
blocks is mapped onto the sectors of the disk sequentially.
o Hard disks drives are organized as a concentric stack of disks or platters’ which rotate
on about a central spindle.
o Each platter has 2 working surfaces.
o Platter is made from aluminum, ceramic, or class, coated with a magnetic materials such
as iron oxide on both sides.
o Each working surface is divided into a number of concentric rings called tracks. The
collection of all tracks that are the same distance from the edge of the platter, ( i.e. all
tracks immediately above one another in the following diagram ) is called a cylinder.
o Each track is further divided into sectors, each containing 512 bytes of data , although
some modern disks use larger sector sizes.
o The data on a hard drive is read by read-write heads. The standard configuration uses
one head per surface, each on a separate arm, and controlled by a common arm
assembly which moves all heads simultaneously from one cylinder to another.
o Each storage unit on a disk can be identified by a 3-coordinate system.
1. Cylinder (C) 2. Head/Side (H) 3. Sector (S)
o During operation the disk rotates at high speeds such as 7200 rpm etc.,
o The transfer rate is the rate at which data flow between the drive and the computer.
o The positioning time, sometimes called the access time, consists of the time to move
the disk arm to the desired cylinder, called the seek time, and the time for the desired
sector to rotate to the disk head, called the rotational latency.
o The disk bandwidth is the total number of bytes transferred, divided by the total time
between the first request for service and the completion of the last transfer.
Multiple I/O requests may arrive by different processes and only one I/O request can
be served at a time by disk controller. Thus other I/O requests need to wait in waiting
queue and need to be scheduled.
Two or more request may be far from each other so can result in greater disk arm
movement.
Hard drives are one of the slowest parts of computer system and thus need to be
accessed in an efficient manner.
The Disk’s speed and performance are based on the following parameters which categorises
the type of Disk Scheduling Algorithms.
Seek Time:Seek time is the time taken to locate the disk arm to a specified track where
the data is to be read or write. So the disk scheduling algorithm that gives minimum
average seek time is better.
Rotational Latency: Rotational Latency is the time taken by the desired sector of disk to
rotate into a position so that it can access the read/write heads. So the disk scheduling
algorithm that gives minimum rotational latency is better.
Transfer Time: Transfer time is the time to transfer the data. It depends on the rotating
speed of the disk and number of bytes to be transferred.
Disk Access Time: Disk Access Time = Seek Time + Rotational Latency + Transfer
Time
Disk Response Time: Response Time is the average of time spent by a request waiting
to perform its I/O operation. Average Response time is the response time of the all
requests. Variance Response Time is measure of how individual request are serviced
with respect to average response time. So the disk scheduling algorithm that gives
minimum variance response time is better.
Whenever a process needs I/O to or from the disk, it issues a system call to the
operating system. If the desired disk drive and controller are available, the request can be
serviced immediately. If it is busy, any new requests for service will be placed in the pending
queue. For a multiprogramming system with many processes, the disk queue may often
have several pending requests. Thus, when one request is completed, the operating system
chooses which pending request to service next. For this, the operating system use the
following various disk-scheduling algorithms.
The following disk scheduling algorithms are used to reduce the seek time of all requests
and hence the head movement:
i) First Come-First Serve (FCFS) ii) Shortest Seek Time First (SSTF) iii) Elevator
(SCAN) iv) Circular SCAN (C-SCAN) v) LOOK vi) C-LOOK
This is the simplest form of disk scheduling . In the first-come, first-served (FCFS) algorithm,
requests are processed in the order that they arrive. This is very easily implemented with
a FIFO queue; when Processes come in, they are put at the end of the queue.
In SSTF (Shortest Seek Time First), requests having shortest seek time are executed first.
So, the seek time of every request is calculated in advance in queue and then they are
scheduled according to their calculated seek time. As a result, the request near the disk arm
will get executed first. SSTF is certainly an improvement over FCFS.
The order of processes after serviced as per SSTF : 100,89,132,189,42,23
In SCAN algorithm the disk arm moves into a particular direction and services the requests
coming in its path and after reaching the end of disk, it reverses its direction and again
services the request arriving in its path. So, this algorithm works like an elevator and hence
also known as elevator algorithm. As a result, the requests at the midrange are serviced
more and those arriving behind the disk arm will have to wait.
Disadvantages: 1) Long waiting time for requests for locations just visited by disk arm.
v) LOOK:
It is similar to the SCAN disk scheduling algorithm except the difference that the disk arm in
spite of going to the end of the disk goes only to the last request to be serviced in front of the
head and then reverses its direction from there only. Thus it prevents the extra delay which
occurred due to unnecessary traversal to the end of the disk.
RAID is a method of combining several hard disk drives into one logical unit. RAID arrays
appear to the operating system as a single logical hard disk. Here the disk drives are
independent, and are multiple in number.
The main advantage of RAID, is that RAID is fault tolerant. In most of the RAID level's data
is redundant in multiple disks, so even if one disk fails, or even two sometimes, the data will
be safe and the operating system will not be even aware of the failure. DATA loss is
prevented due to the fact that data can be recovered from the disk that are not failed.
Stripping
Mirroring
Parity
1. Striping :
RAID is collection of multiple disk’s and in these disk ,predefined number of contiguously
addressable disk blocks are defined which are called as strips and collection of such strips in
aligned in multiple disk is called stripe.
Fig. 4.9 Striping
Hard disk is a collection of multiple addressable blocks and these blocks are stacked
together and called strip and multiple such hard disks are placed parallel or serially. Then
such combination of disk is called stripe.
2. Mirroring :
Mirroring is a mechanism in which the same data is written to another disk drive. "mirroring"
is simply a pair of disk drives which store duplicate data, but appear to the computer as a
single drive; the number of drives in the array will always be an even number. The main
advantage of mirroring(multiple sets of same data on two disks), is that it provides 100
percent redundancy.
Suppose there are two drives in mirroring mode, then both of them will contain an exact
same copy of data. So even if one disk fails, the data is safe on the other.
When the failed disk is replaced with a new disk, the controller copies the data from the
surviving disk of the mirrored pair. Data is simultaneously recorded on both the disk.
Though this type of RAID gives you highest availability of data but it is costly as it requires
double amount of disk space and thus increasing the cost.
3. Parity :
Mirroring involves high cost, so to protect the data new technique is used with striping called
parity. This is reliable and low cost solution for data protection. In this method and
additional HDD or disk is added to the stripe width to hold parity bit.
Parity is a redundancy check that ensures full protection of data without maintaining a full set
of duplicate data.
Fig.4.11 Parity
The parity bits are used to re-create the data at the time of failure. Parity information can be
stored on separate, dedicated HDDs or distributed across all the drives in a RAID set. In the
above image, parity is stored on a separate disk.
The first three disks, labeled D, contain the data. The fourth disk, labeled P, stores the parity
information, which in this case is the sum of the elements in each row. Now, if one of the
Disks (D) fails, the missing value can be calculated by subtracting the sum of the rest of the
elements from the parity value.
RAID 0: In a RAID 0 system data are split up in blocks that get written across all the drives
in the array. By using multiple disks (at least 2) at the same time, this offers superior I/O
performance. This configuration has striping but no redundancy of data. It offers the best
performance but no fault-tolerance.
Fig 4.12 RAID 0
Advantages
RAID 0 offers great performance, both in read and write operations. There is no
overhead caused by parity controls.
All storage capacity is used, there is no overhead.
The technology is easy to implement.
Disadvantages
RAID 0 is not fault-tolerant. If one drive fails, all data in the RAID 0 array are lost. It
should not be used for mission-critical systems.
RAID 1: Also known as disk mirroring. Data are stored twice by writing them to both the data
drive (or set of data drives) and a mirror drive (or set of drives) . If a drive fails, the controller
uses either the data drive or the mirror drive for data recovery and continues operation. You
need at least 2 drives that duplicate the storage of data for a RAID 1 array.There is no
striping. Read performance is improved since either disk can be read at the same time. Write
performance is the same as for single disk storage.
In a RAID 0 system data are split up in blocks that get written across all the drives in the
array. By using multiple disks (at least 2) at the same time, this offers superior I/O
performance.
Fig 4.13 RAID 1
Advantages
RAID 1 offers excellent read speed and a write-speed that is comparable to that of a
single drive.
In case a drive fails, data do not have to be rebuild, they just have to be copied to the
replacement drive.
RAID 1 is a very simple technology.
Disadvantages
The main disadvantage is that the effective storage capacity is only half of the total
drive capacity because all data get written twice.
Software RAID 1 solutions do not always allow a hot swap of a failed drive. That
means the failed drive can only be replaced after powering down the computer it is
attached to. For servers, this is not suitable .
RAID 2: This configuration uses striping across disks with some disks storing error
checking and correcting (ECC) information. It has no advantage over RAID 3 and is no
longer used.
Fig. 4.14 RAID 2
RAID 3: This technique uses striping and dedicates one drive to storing parity
information. The embedded ECC information is used to detect errors. Data recovery is
accomplished by calculating the exclusive OR (XOR) of the information recorded on the
other drives. Since an I/O operation addresses all drives at the same time, RAID 3
cannot overlap I/O. For this reason, RAID 3 is best for single-user systems with long
record applications.
RAID 4: This level uses large stripes, which means you can read records from any single
drive. This allows you to use overlapped I/O for read operations. Since all write
operations have to update the parity drive, no I/O overlapping is possible. RAID 4 offers
no advantage over RAID 5.
Fig. 4.16 RAID 4
RAID 5: This level is based on block-level striping with parity. This is the most common
secure RAID level. It requires at least 3 drives but can work with up to 16. Data blocks are
striped across the drives and on one drive a parity checksum of all the block data is written.
The parity data are not written to a fixed drive, they are spread across all drives, as the
drawing below shows. Using the parity data, the computer can recalculate the data of one of
the other data blocks, should those data no longer be available. That means a RAID 5 array
can withstand a single drive failure without losing data or access to data. Although RAID 5
can be achieved in software, a hardware controller is recommended. Often extra cache
memory is used on these controllers to improve the write performance.
Advantages
Read data transactions are very fast while write data transactions are somewhat
slower (due to the parity that has to be calculated).
If a drive fails, you still have access to all data, even while the failed drive is being
replaced and the storage controller rebuilds the data on the new drive.
Disadvantages
RAID 6: This technique is similar to RAID 5 but includes a second parity scheme that is
distributed across the drives in the array. The use of additional parity allows the array to
continue to function even if two disks fail simultaneously. However, this extra protection
comes at a cost. RAID 6 arrays have a higher cost per gigabyte (GB) and often have
slower write performance than RAID 5 arrays.
Disadvantages
Write data transactions are slowed down due to the parity that has to be calculated.
Drive failures have an effect on throughput, although this is still acceptable.
This is complex technology. Rebuilding an array in which one drive failed can take a
long time.
4.2 File Management
Most computer systems employ secondary storage devices such as magnetic disk, magnetic
tape, optical media, flash drives etc. to provide cheap, non-volatile storage for programs and
data. The programs, and the user data they work with, are stored in discrete storage units
called files.
Important Tasks of the File management system of the operating system :
i) allocating space for files on secondary storage media as and when required.
ii) keeping track of creating, destroying, organizing, reading, writing, modifying,
moving, and controlling access to files; and
iii) management of resources used by files.
iv) keeping access times (the time required to write data to or read data from
secondary storage) to a minimum.
A file is a named collection of related information that is recorded on secondary storage such
as magnetic disks, magnetic tapes and optical disks. In general, a file is a sequence of bits,
bytes, lines or records which is created by users.
A File Structure should be according to a required format that the operating system can
understand.
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 These are the files that contain user information. These may have text,
databases or executable program. The user can apply various operations on such files like
add, modify, delete or even remove the entire file.
Directory files These files contain list of file names and other information related to these
files.
Special files These files are also known as device files. These files represent physical
device like disks, terminals, printers, networks, tape drive etc.
These files are of two types −
A file has generally the following attributes but vary from operating system to another:
Name: The symbolic file name is the only information kept in human readable form.
Identifier: This unique tag, usually a number, identifies the file within the file system; it is the
non-human readable name for the file
Type: This information is needed for those systems that support different types.
Location: This information is a pointer to a device and to the location of the file on that
device.
Size: The current size of the file (in bytes, words, or blocks), and possibly the maximum
allowed size are included in this attribute.
Time, date, and user identification: This information may be kept for creation, last
modification, and last use. These data can be useful for protection, security, and usage
monitoring.
A file is an abstract data type. To define a file properly, we need to consider the
operations that can be performed on files.
Six basic file operations. The OS can provide system calls to create, write, read,
reposition, delete, and truncate files.
4.2.4.1 Directory
A directory is a location for storing files on the computer. Directories are found in a
hierarchical file system, such as Linux, MS-DOS, OS/2, and Unix. A directory is an
organizational unit, or container, used to organize folders and files into a hierarchical
structure. Directories contain bookkeeping information about files. A directory is considered
as a file cabinet that contains folders that contain files. Many graphical user interfaces (GUI)
use the term folder instead of directory.
• In the above example, C: is the drive letter and the current directory is
System32, which is a subdirectory of the Windows directory.
Uses of Directories :
A directory entry provides the info needed to find the disk data blocks of a file
disk address of first block and size
address of first block
number of associated i-node
File attributes and file names can be stored in the directory entry (Windows)
or in its i-node (Unix).
File name may have variable length and long file names contain 255 chars.
4.2.4.3 Types of Directories : There are many types of directory structure in
Operating System. They are as follows :-
In Single Level Directory , all files are in the same directory. Simple to implement,
but each file must have a unique name.
Limitations of Single Level Directory
a) Since all files are in the same directory, they must have unique name.
b) If two user call their data free test, then the unique name rule is violated.
c) Files are limited in length.
d) Even a single user may find it difficult to remember the names of all files as
the number of file increases.
e) Keeping track of so many file is a difficult task.
8. The root of a tree is Master File Directory (MFD). Its direct descendents are User File
Directory (UFD). The descendents of UFD's are file themselves. The files are the
leaves of the tree.
A directory (or Sub directory) contains a set of files or sub directories. All directories
has the same internal format. Each user / process has the concept of a current
directory from which all ( relative ) searches take place.
Files may be accessed using either absolute pathnames ( relative to the root of the
tree ) or relative pathnames ( relative to the current directory. )
Directories are stored the same as any other file in the system, except there is a bit
that identifies them as directories, and they have some special structure that the OS
understands.
File Allocation :
File allocation is a technique used to allocate space for files so that disk space is
utilized effectively and files can be accessed quickly.
Disks are divided into physical blocks (sectors on a track).
Files are divided into logical blocks (subdivisions of the file).
Logical block size = some multiple of a physical block size.
The operating system or file management system is responsible for allocating blocks
to files.
Space is allocated to a file as one or more portions (contiguous set of allocated disk
blocks). A portion is the logical block size.
File allocation table (FAT) - data structure used to keep track of the portions
assigned to a file.
A preallocation policy requires that the maximum size of a file be declared at the time
of the file creation request.
Dynamic allocation allocates space to a file in portions as needed.
1. Contiguous Allocation
FileA 2 3
File B 9 5
File C 18 8
File D 30 2
File E 26 3
4.23 Contiguous File Allocation
Advantage:
Disadvantage:
There is no external fragmentation to worry about because only one block at a time is
needed. This type of physical organization is
Fig 4.24 Linked File Allocation
Advantages:
Disadvantages:
Each file has an index block that is an array of disk block addresses.
The i-th entry in the index block points to the i-th block of the file.
A file’s directory entry contains a pointer to its index.
Hence, the index block of an indexed allocation plays the same role as the page
table. Index allocation supports both sequential and direct access without external
fragmentation.
The indexed allocation suffers from wasted space. The index block may not be fully
used (i.e., internal fragmentation).
The number of entries of an index table determines the size of a file. To overcome
this problem, we can have multiple index blocks and chain them into a linked list.
We can also have multiple index blocks, but make them a tree just like the indexed
access method.
Another alternative is that we can have a combination of both.
4.25 Indexed File Allocation
Advantages:
File access mechanism refers to the manner in which the records of a file may be accessed.
There are several ways to access files −
Sequential access
Direct/Random access
Indexed sequential access
Sequential access
A sequential access is that in which the records are accessed in some sequence, i.e., the
information in the file is processed in order, one record after the other. This access method
is the most primitive one. Example: Compilers usually access files in this fashion.
Direct/Random access
Disks provide the bulk of secondary storage on which a file system is maintained. They have
two characteristics that make them a convenient medium for storing multiple files:
They can be rewritten in place; it is possible to read a block from the disk, to modify
the block, and to write it back into the same place.
They can access directly any given block of information on the disk. Thus, it is simple
to access any file either sequentially or randomly, and switching from one file to
another requires only moving the read write heads and waiting for the disk to rotate.
Rather than transferring a byte at a time, to improve I/O efficiency, I/O transfers between
memory and disk are performed in units of blocks. Each block is one or more sectors.
Depending on the disk drive, sectors vary from 32 bytes to 4,096 bytes, they are 512 bytes.
File Structure
byte sequence
record sequence
tree
a. Byte Sequence:
The file in Fig. (a) is just an unstructured sequence of bytes. In effect, the
operating system does notknow or care what is in the file. All it sees are bytes.
Any meaning must be imposed by user-level programs. Both UNIX and Windows
98 use this approach.
b. Record Sequence:
In this model, a file is a sequence of fixed-length records, each with some internal
structure. Central to the idea of a file being a sequence of records is the idea that
the read operation returns one record and the write operation overwrites or
appends one record. As a historical note, when the 80-column punched card was
king many (mainframe) operating systems based their file systems on files
consisting of 80-character records, in effect, card images
c. Tree:
In this organization, a file consists of a tree of records, not necessarily all the
same length, eachcontaining a key field in a fixed position in the record. The tree
is sorted on the key field, to allow rapid searching particular key.
ii) Partitioning : This is a process which divides a disk into one or more regions, writing data
structures to the disk to indicate the beginning and end of the regions. This level of
formatting often includes checking for defective tracks or defective sectors.
iii) High-level formatting : After low-level formatting is complete, we have a disk with
tracks and sectors--but nothing written on them. High-level formatting is the process of
writing the file system structures , cluster size, partition label, etc., on the newly created
partition on the disk that make the disk to be used for storing programs and data. This is a
fast operation, and is sometimes referred to as quick formatting.. And we can also say high-
level formatting just clears data on hard disk, generates boot information, initializes FAT, and
labels logical bad sectors when the partition has completed .This formatting includes the
data structures used by the OS to identify the logical drive or partition's contents. This may
occur during operating system installation, or when adding a new disk. This formatting is
made by users themselves.
4.3 Security and protection
Security refers to providing a protection system to computer system resources such as CPU,
memory, disk, software programs and most importantly data/information stored in the
computer system. If a computer program is run by an unauthorized user, then he/she may
cause severe damage to computer or data stored in it. So a computer system must be
protected against unauthorized access, malicious access to system memory, viruses, worms
etc.
Protection refers to a mechanism for controlling the access of programs, processes, or users
to the resources defined by a computer system. This mechanism must provide a means for
specifying the controls to be imposed, together with a means of enforcement.
Trojan Horse − Such program traps user login credentials and stores them to send
to malicious user who can later on login to computer and can access system
resources.
Trap Door − If a program which is designed to work as required, have a security hole
in its code and perform illegal action without knowledge of user then it is called to
have a trap door.
Logic Bomb − Logic bomb is a situation when a program misbehaves only when
certain conditions met otherwise it works as a genuine program. It is harder to detect.
Virus − Virus as name suggest can replicate themselves on computer system. They
are highly dangerous and can modify/delete user files, crash systems. A virus is
generatlly a small code embedded in a program. As user accesses the program, the
virus starts getting embedded in other files/ programs and can make system
unusable for user
Worm − Worm is a process which can choke down a system performance by using
system resources to extreme levels. A Worm process generates its multiple copies
where each copy uses system resources, prevents all other processes to get
required resources. Worms processes can even shut down an entire network.
Port Scanning − Port scanning is a mechanism or means by which a hacker can
detects system vulnerabilities to make an attack on the system.
Denial of Service − Denial of service attacks normally prevents user to make
legitimate use of the system. For example, a user may not be able to use internet if
denial of service attacks browser's content settings.
1. Physical - The site or sites containing the computer systems must be physically secured
against harmful entry by intruders. Both the machine rooms and the terminals or
workstations that have access to the machines must be secured.
2.Human - There is some concern that the humans who are allowed access to a
system be trustworthy, and that they cannot be coerced into breaching security.
However more and more attacks today are made via social engineering, which
basically means fooling trustworthy people into accidentally breaching security.
3.Operating System - The OS must protect itself from security breaches, such as
runaway processes ( denial of service ), memory-access violations, stack overflow
violations, the launching of programs with excessive privileges, and many others.
4. Network - Much computer data in modern systems travels over private leased lines,
shared lines like the Internet, wireless connections, or dial-up lines. Intercepting these data
could be just as harmful as breaking into a computer; and interruption of communications
could constitute a remote denial-of-service attack, diminishing users' use of and trust in the
system.
4.3.2.2 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 −
Username / Password − User need to enter a registered username and password
with Operating system to login into the system.
User card/key − User need to punch card in card slot, or enter key generated by key
generator in option provided by operating system to login into the system.
User attribute - fingerprint/ eye retina pattern/ signature − User need to pass
his/her attribute via designated input device used by operating system to login into
the system.
i) Passwords
This method is the most commonly used for authentication. When the user identifies
himself by user ID or account name, he is asked for a password. If the user-supplied
password matches the password stored in the system, the system assumes that the account
is being accessed by the owner of that account.
Passwords are often used to protect resources in the computer system like files. Whenever
a request is made to use the resource, the passwordmust be given. If the password is
correct, access is granted. Different passwords may be associated with different access
rights. For example, different passwords may be used for reading files, appending files, and
updating files.
Passwords are extremely common because they are easy to understand and use.
Unfortunately, passwords can often be guessed, accidentally exposed, sniffed, or illegally
transferred from an authorized user to an unauthorized one. So, the operating system uses
encryption to avoid the necessity of keeping its password list secret. Each user has a
password. The system uses a function to encode all the passwords. Only encoded
passwords are stored.
When a user presents a password, it is encoded and compared against the stored encoded
password. Even if the stored encoded password is seen, it cannot be decoded, so the
password cannot be determined. Thus, the password file does not need to be kept secret.
One-time passwords provide additional security along with normal authentication. In One-
Time Password system, a unique password is required every time user tries to login into the
system. Once a one-time password is used, then it cannot be used again. One-time
password are implemented in various ways.
Random numbers − Users are provided cards having numbers printed along with
corresponding alphabets. System asks for numbers corresponding to few alphabets
randomly chosen.
Secret key − User are provided a hardware device which can create a secret id
mapped with user id. System asks for such secret id which is to be generated every
time prior to login.
Network password − Some commercial applications send one-time passwords to
user on registered mobile/ email which is required to be entered prior to login.
iv) Bio-metrics
The biometric technologies involved are based on the ways in which individuals can be
uniquely identified through one or more distinguishing biological traits, such as fingerprints,
hand geometry, earlobe geometry, retina and iris patterns, voice waves, keystroke
dynamics, DNA and signatures. Biometric authentication is the application of that proof of
identity as part of a process validating a user for access to a system. Biometric technologies
are used to secure a wide range of electronic communications, including enterprise security,
online commerce and banking -- even just logging in to a computer or smart phone.
Biometric authentication systems compare the current biometric data capture to stored,
confirmed authentic data in a database. If both samples of the biometric data match,
authentication is confirmed and access is granted. The process is sometimes part of a
multifactor authentication system. For example, a smart phone user might log on with his
personal identification number (PIN) and then provide an iris scan to complete the
authentication process.
Summary
Disks provide the bulk of secondary storage for modern computer systems.
storage capacity of a disk drive =
No. of working surfaces( or heads) x No. of tracks per surface x No. of sectors per
track x No. of bytes per sector.
Disk speed has the following three parameters :The transfer rate The positioning
time, sometimes called the access time, The disk bandwidth
Disk scheduling is done by operating systems to schedule I/O requests arriving for
disk.i.e. I/O scheduling.
Disk Drive Performance parameters:Seek Time,Rotational Latency,.Transfer
Time,Disk Access Time, Disk Response Time.
Disk Scheduling Algorithms are First Come-First Serve (FCFS) ,Shortest Seek Time
First (SSTF) , Elevator (SCAN) , Circular SCAN (C-SCAN) , LOOK and C-LOOK
RAID stands for Redundant Array of Inexpensive (or sometimes
"Independent") Disks.
RAID is a method of combining several hard disk drives into one logical unit.
Characteristics used in RAID are:Stripping,Mirroring,Parity
RAID 0: In a RAID 0 system data are split up in blocks that get written across all
the drives in the array.
RAID 1: known as disk mirroring. Data are stored twice by writing them to both
the data drive (or set of data drives) and a mirror drive (or set of drives)
RAID 2: This configuration uses striping across disks with some disks storing
error checking and correcting (ECC) information.
RAID 3: This technique uses striping and dedicates one drive to storing parity
information.
RAID 4: This level uses large stripes, which means you can read records from
any single drive
RAID 5: This level is based on block-level striping with parity
RAID 6: This technique is similar to RAID 5 but includes a second parity
scheme that is distributed across the drives in the array.
Files are discrete stored units used to store the programs, and the user data they
work with.
A file is a named collection of related information that is recorded on secondary
storage such as magnetic disks, magnetic tapes and optical disks.
There are different types of files--Ordinary files, Directory files,Special files
File Attributes are Name, Identifier, Type, Location, Size,Protection, Time, date, and
user identification:
Review Questions
Part – A ( 2 marks)
1. List the Various types of I/O devices.
2. Define: Disk Scheduling.
3. List any four types of Disk Scheduling.
4. What are Sectors?
5. Define: Cylinder.
6. What is a Track?
7. How will you find the capacity of a Disk?
8. What is a RAID array?
9. Define: Data striping.
10. What do you mean by Disk mirroring?
11. What is Parity?
12. Define a file.
13. What are the main tasks of File Management.
14. List the File attributes.
15. What are the various operations that can be done on files?
16. What is a Directory?
17. List the various types of directories.
18. List the advantages of two level directories?
19. Draw a tree based Directory structure.
20. Define : Contiguous allocation of disk space.
21. List the advantages of Indexed Allocation.
22. Give the difference between sequential and random access methods.
23. What is record sequence file structure?
24. What is Low level Disk formatting?
25. Define: Security
26. Name some of the security threats.
27. Define: Authentication.
28. What is the use of Password?
29. Name some areas where onetime passwords are used?
30. Mention some of the biological traits that are used in Biometrics.
Part – B ( 3 marks )
UNIT – V
LINUX – A CASE STUDY
LEARNING OBJECTIVES
Understand the history and the features of the Linux operating system.
Know about FSF/GNU and the various flavors of Linux OS.
Differentiate UNIX and Linux operating systems.
Describe the architecture of Linux operating system.
Explain the desktop environment of Linux OS.
Explain EXT2 and VFS file systems.
List and explain different types of file.
Explain the concept of file permission and file security.
Define and explain mounting and unmounting the file system.
UNIT – V
LINUX – A CASE STUDY
LEARNING OBJECTIVES
Understand the history and the features of the Linux operating system.
Know about FSF/GNU and the various flavors of Linux OS.
Differentiate UNIX and Linux operating systems.
Describe the architecture of Linux operating system.
Explain the desktop environment of Linux OS.
Explain EXT2 and VFS file systems.
List and explain different types of file.
Explain the concept of file permission and file security.
Define and explain mounting and unmounting the file system.
5.1 INTRODUCTION
Operating systems are an essential part of any computer system. An operating
system is the first piece of software that the computer executes when you turn the machine
on. The operating system loads itself into memory and begins managing the resources
available on the computer. The most popular operating systems in use today are Windows,
Mac OS, UNIX and Linux. Linux is a version of UNIX that has gained popularity in recent
years.
Key to the success of Linux has been the availability of free software packages under
theFree Software Foundation (FSF). FSF's goal is stable, platform-independentsoftware that
is free, high quality, and embraced by the user community. FSF's GNU projectprovides tools
for software developers, and the GNU Public License (GPL) is the FSF seal ofapproval.
.
Multi-User − Linux is a multiuser operating system. At same time multiple users can
access system resources like memory, ram and application programs.
Multitasking: Linux has the ability to handle more than one job at a time. For
example you have executed a command for sorting a huge list and simultaneously
typing in a notepad.
Portable − Portability was the one of the main features that made Linux so
popular.Linuxand its application can works on different types of hardware. A Linux
kernel and application program supports their installation on any kind of hardware
platform.
Open Source − Linux source code is freely available. Multiple teams work to
enhance the capability of Linux operating system and it is continuously evolving.
Hierarchical File System − Linux provides a standard file structure in which system
files and user files are arranged.
Shell − Linux provides a special interpreter program which can be used to execute
commands of the operating system.
Security:Security is a very important part of any operating system. Linux provides
several security concepts for protecting their users from unauthorized access of their
data and system.It provides user security using authentication features like password
protection, controlled access to specific files and encryption of data.
Communication: Linux has an excellent feature for communication. It can be within
the network of a single main computer, or between two or more such
computer networks.
2 Linux can be freely distributed, downloaded freely, distributed through magazines, books etc. Different flavors of Unix have different cost structures.
3 Linux is user friendly OS Unix is not user friendly OS
4 General user can use Linux. For Example From home users to developers can use Linux Unix operating systems were developed mainly for mainframes, servers and workstations. So normal users cannot easily use Unix .
5 Linux can be instal ed on a wide variety of computer hardware, ranging from mobile phones, tablet computers and video game consoles, to mainframes and supercomputers. Unix is restricted. It cannot be installed in any hardware.
6 Linux typically provides two GUIs, KDE and Gnome Initial y Unix was a command based OS, but later a GUI was created called Common Desktop Environment.
7 Linux supports ext2, procfs, sysfs, ramfs and tmpfs file systems. Unix supportsgpfs, jfs, hfs, zfs, xfs file systems.
Hardware layer – Hardware consists of all peripheral devices (RAM/ HDD/ CPU
etc.).
Kernel – Core component of operating system, for all basic input/output
management it interacts directly with the hardware.
Shell –It is an interface between the user and the kernel. It hides the complexity of
the kernel’s functions from users. It receives commands from user and executes
kernel’s functions.
Application Software –An utility programs that provide the user most of the
functionalities of an operating systems
Users – System users, who interacts directly with the system and application
software’s.
7 http://puppylinux.org/
T i n y C o r e Very small footprint (10MB once installed) Linux, suitable for old hardware or low specification machines
8 http://www.tinycorelinux.com/
5.1.5 FSF/GNU
5.1.5.1 FREE SOFTWARE FOUNDATION(FSF)
The Free Software Foundation (FSF) is founded by Richard Stallman on 4 October
1985 to support the free software movement, which promotes the universal freedom to
study, distribute, create, and modify the computer software.
Free software means users of a program have the four essential freedoms:
The freedom to run the program as your wish, for any purpose (freedom 0).
The freedom to study how the program works, and adapt it to your needs (freedom
1).
The freedom to redistribute copies so you can help your neighbor (freedom 2).
The freedom to improve the program, and release your improvements to the public,
so that the whole community benefits (freedom 3).
5.1.5.2 GNU
Desktop is thearea of a
displayscreenwhereimages,windows,iconsandothergraphicalitemsappear. There are two
popular desktop environments supported by Linux operating system are GNOME and KDE.
5.1.6.1 GNOME
GNOMEstands for GNU Network Object Model Environment. It was founded in 1997.
GNOME became extremely popular due to its simplicity and ease of use. It is a graphical
desktop environment for Linux operating system. It composed entirely of free and open
source software.
5.1.6.2 KDE
KDE stands for K Desktop Environment. It is a desktop environment for Linux based
operation system. It is an open source graphical desktop environment. KDE provides Linux
users a graphical interface to choose their own customized desktop environment.
In EXT2 file systemthe data available in files is divided intonumber of data blocks. All
the data blocks are of the same length. Every file's size is rounded up to an integral number
of blocks. If a file with size 1025 bytes will occupy two 1024 byte blocks. All of the blocks in
the file system doesn’thold the data. Some block contains the information about the structure
of the file system.
The inode is the basic building block in the EXT2 file system. The inode number is a
unique number used to identify the file or directory. All the inodes are kept in a table called
inode table. An inode describes
Figure 5.2 shows the layout of the EXT2 file system.The inode number is used to read
information or data from the file.
Figure 5.3 shows the format of an EXT2 inode, amongst other information, it contains
the following fields:
Mode
This holds two pieces of information. They are
what this inode describes
The permissions that users have to it.
Owner Information
This filed indicates the owner of the file or directory.
Size
This field indicates the size of the file in bytes.
Timestamps
This filed indicates the time that the inode was created and the last modified.
Datablocks
This field indicates the pointers to the blocks that contain the data. The first twelve
are pointers to the physical blocks containing the data described by this inode and
the last three pointers contain more and more levels of indirection.
Figure 5.4 indicates the key ingredients of the Linux file system strategy. To access
any file, a user process issues a requestto VFS file scheme. The VFSconverts the request
into an internal file system call which allows the user to access the corresponding file
system. So the user can access any file in the directory treewithout the knowledge of the
location of the file where it is stored.
The Virtual File System (VFS) is used to manage all the file systems that are
mounted in the Linux operating system. To do this, VFS maintains data structures that
describe the whole (virtual) file system and the mounted file systems.VFS describes the files
in terms of superblocks and inodes.
The superblock object consists of a number of data items. Examples include the following:
iv) The device that this file system is mounted on
v) The basic block size of the file system
vi) Dirty flag, to indicate that the superblock has been changed but not written back to
disk
vii) File system type
viii) Flags, such as a read-only flag
ix) Pointer to the root of the file system directory
x) List of open files
xi) Semaphore for controlling access to the file system
xii) List of superblock operations
An inode is associated with each file. The inode holds all the informationabout a file
except its name and the actual data contents of the file. Itemscontained in an inode include
owner, group, permissions, access times for afile, size of data it holds, and number of links.
The inode also includes inode operations. The methods defined for the inode include
the following
Regular files
Directory files
Special files
a. Block file(b)
b. Character device file(c)
c. Named pipe file or just a pipe file(p)
d. Symbolic link file(l)
e. Socket file(s)
o Regular files
Regular file contains the normal data. These files are indicated with "-" at the starting
of the line when we use ls –l command. The regular file may be
a. A Readable file
b. A Binary file
c. An Image file
d. A Compressed file
Example
$ ls - l
The above two files are the regular files created by the user.
v) Directory file
Directory contains regular files, folders and special files.This type of files is normally
blue in color. These files are indicated with "d" at the starting of the line when we use ls –l
command.
Example
$ ls - l
Block file
These files are hardware files most of them are present in /dev. These files are
indicated with "b" at the starting of the line when we use ls –l command.
Example
$ ls - l
brw-rw---- 1 root disk 8, 1 2010-02-15 09:35 sda1
brw-rw---- 1 root disk 8, 2 2010-02-15 09:35 sda2
This type of files provides a serial stream of input or output. These files are indicated
with "c" at the starting of the line when we use ls –l command.
Example
$ ls–l
Pipe files
The other name of pipe is a “named” pipe, which is sometimes called a FIFO. FIFO
refers to the property that the order of bytes going in is the same coming out.These files are
indicated with "p" at the starting of the line when we use ls –l command.
Example
$ ls–l
Example
$ ls–l
Socket files
Example
$ ls–l
To view the permission of the file or directory ls –l command is used. For example
$ ls – l
In the above output the first ten characters shows the file permission. The first
character indicates the special permission flag that can vary based on the type of the file.
The first three ‘rwx’ indicates the permission for the owner. The second three ‘rwx’ indicates
the permission given to the group. The last three ‘rwx’ indicates the permission for all users.
V a l u e P e r m i s s i o n D e s c r i p t i o n
0 - - - N o p e r m i s s i o n
1 - - x Execute permission
2 - w - Write permission
3 - w x Write and Execute
4 r - - Read permission
5 r - x Read and Execute
6 r w - Read and W rite
7 r w x Read, Write and Execute
The table above shows the abbreviation of the different types of users used in chmod
command. Let us consider the following examples.
Example1
$ls – l
-r-xr-xr-x file1
In the above example all the three types of users have read and execute permission only. To
change the file permission, then type
$chmodu +w file1
$chmod g –x file1
After executing the above command the permission for file1 will be changed like the
following
$ ls – l
-rwxr--r-x file1
Example2
$chmod 640 file1
The above command gives read and write permission to owner, read permission to group
and no permission for all user.
All the files in Linux operating system are arranged in a tree like structure rooted with
/. The mount command attaches a file system located on some drives to the file hierarchy.
All the files are to be mounted before the actual use.
Example
$mount –t cdrom /dev
5.2.6 UNMOUNTING
All the files are automatically unmounted after its use. Unmounting is nothing but
detaching the specified file system from the file hierarchy. A file system cannot be
unmounted when it is busy. The general form is
$ unmounts device-name
Example
$ unmounts dev/fd1
Summary
Linux is a free and open source operating system. It was developed by Linus
torvaldsa student of computer science in the University of Helsinki.
Important features of Linux operating system.-Multi-User, Multitasking ,Portable
,Open Source ,Hierarchical File System , Security and Communication.
Linux architecture has Hardware layer ,Kernel ,Shell ,Application Software parts.
o The Free Software Foundation (FSF) to support the free software movement,
which promotes the universal freedom to study, distribute, create, and modify
the computer software.
GNU is a Unix-like operating system. It is a collection of many programs like
applications, libraries, developer tools, even games.
The linux desktop environment are -GNOME , KDE
The linux file system has EXT2, and virtual file system.
The different types of files in Linux are Regular files , Directory files and Special files
The different special files are
o Block file(b)
o Character device file(c)
o Named pipe file or just a pipe file(p)
o Symbolic link file(l)
o Socket file(s)
There are many security features are already built in the Linux operating system. But
an important potential vulnerability is granting file permission.
Each file and directory has three types of users. They are Owner,Group,All users.
The three levels of file security are
o Read – Read the content of the file or directory
o Write – Write or modify a file or directory
o Execute – Execute the file or directory
The mount command attaches a file system located on some drives to the file
hierarchy. All the files are to be mounted before the actual use.
All the files are automatically unmounted after its use. Unmounting is nothing but
detaching the specified file system from the file hierarchy.
REVIEW QUESTIONS
PART - A
1. Who developed Linux?
2. Why Linux is known as free software?
3. Expand FSF/GNU.
4. What is meant by GPL?
5. List any three flavors of Linux.
6. Define directory.
7. Define inode number.
8. List the different types of files used in Linux.
9. Which command is used to modify the file permission?
PART –B
List the features of Linux.
Differentiate Linux and Unix.
Write briefly about GNOME desktop.
Write briefly about KDE desktop.
Define mounting and unmounting
PART – C
With neat sketch explain the architecture of Linux.
Explain EXT2 file system with neat diagram
Explain virtual file system.
Explain the different types of files supported in Linux.
Explain file security in Linux.
References
http://tldp.org
www.computerhope.com
www.Linux.com