Operating System
Operating System
Operating System
CHAPTER 1
Introduction
1.0 Objectives
1.1 Introduction
1.2 What is operating system
1.2.1 Definition
1.2.2 The Operating System as an Extended Machine
1.2.3 The Operating System as a Resource Manager
1.3 History of operating system
1.3.1 First Generation OS
1.3.2 Second Generation OS
1.3.3 Third Generation OS
1.3.4 Fourth Generation OS
1.3.5 Fifth Generation OS
1.4 Computer hardware
1.4.1 Processor
1.4.2 Memory
1.4.3 Disk
1.4.4 Booting of system
1.5 Let us Sum Up
1.6 List of Reference
1.7 Bibliography
1.8 Unit End Exercise
1.0 Objectives
The objective of the chapter is as follow
To get familiar with core component of operating systems
To understand the different generation of operating system
To understand the different functionality of system
1.1 Introduction
Operating systems provides a clear, best and simple view of the computer to the users.
Operating system performs the function of resource handling and distributing the
resources to the different part of the system
It is the intermediary between users and the computer system and provide a level of
abstraction due to which complicated details can be kept hidden from the user
1.2 What is Operating System
1.2.1 Definition :
Operating System is a system software which acts as an intermediary between
user and hardware.
Operating System keeps the complicated details of the hardware hidden from the
user and provides user with easy and simple interface.
It performs functions which involves allocation of resources efficiently between
user program, file system, Input Output device
Figure 1. Abstract view of Operating system
Reference: Modern Operating system, Fourth edition, Andrew S. Tanenbaum, Herbert Bos
Explanation of Figure 1
The hardware components lies at the bottom of the diagram. It is considered as
the most crucial part of computer system. To protect the hardware from direct
access, it is kept at the lowest level of hierarchy. Hardware components includes
circuits, input output device, monitor etc
Operating system runs in the kernel mode of the system wherein the OS gets an
access to all hardware and can execute all machine instructions. Other part of the
system runs in user mode
Disk is a mechanical device capable of storage which is cheaper and larger than
RAM.
The only problem is that the time to randomly access data on it is slower.
A disk consists metal plats that rotate at 5400, 7200, 10,800 RPM or more.
An arm pivots over the plats from the corner
Each of the heads can read an annular region called a track.
Together, all the tracks for a given arm position form a cylinder.
Each track is divided into some number of sectors, typically 512 bytes per sector.
1.7 Bibliography
Modern Operating System by galvin
1.8 Unit End Exercise
CHAPTER 2
2.0 Objectives
2.1 Introduction
2.2 Different Operating Systems
2.2.1 Mainframe Operating Systems
2.2.2 Server Operating Systems
2.2.3 Multiprocessor Operating System
2.2.4 Personal Operating Systems
2.2.5 Handheld Operating System
2.2.6 Embedded Operating Systems
2.2.7 Sensor-Node Operating System
2.2.8 Real-Time Operating Systems
2.2.9 Smart Card Operating System
2.3 Operating system Concepts
2.4 System Calls
2.4.1 System calls for Process management
2.4.2 System calls for File management
2.4.3 System calls for Directory management
2..4.4 Windows Win32 API
2.5 Operating System
2.5.1 Monolithic System
2.5.2 Layered System
2.5.3 Microkernels
2.5.4 Client Server System
2.5.5 Exokernel
2.5 Let us Sum Up
2.6 List of Reference
2.7 Bibliography
2.8 Unit End Exercise
1.0 Objectives
The objective of the chapter is as follow
To understand the operating system services provided to the users and processes,
To understand the various operating system structures.
To describe various types of operating system
2.1 Introduction
An operating system provides the environment within which programs are
executed.
It is important to understand the goals of the system which will help us to select the
algorithm and strategies for the designing of the system
2.2 Different Operating System
Process: A process is a program which is in execution mode. Each process has an address
space. All data related to process is stored in a table called as process table. All details for
running the program is contained in the process. A process can reside in anyone of the
five states in its life time. There are background and foreground processes running in the
systems carrying out different functions. These processes communicates with each other
using interprocess communication
Address space: Computer need a mechanism to distinguish between process sitting inside
the main memory. This is done by allocating he process to an address space. computers
addresses are 32 or 64 bits, giving an address space of 232 or 264 bytes. Virtual address
spaces are playing an important role in dealing with the problem of insufficient memory
space.
Files are the data which the user want to retrieve back from the computer. Operating
systems is supposed to maintain the data in hard disk and retrieve it from it when ever
needed. Operating system arranges files in the form of hierarchy. The data goes inside the
directory.
Shell
Shell is the command interpreter for UNIX. Shell become the intermediate between the
user on the terminal and the operating systems. Every shell has a terminal for entering
the data and to get the output. Instructions are given in the form of commands to the
computer.
mkdir is a system call that creates and empty directories, whereas rmdir removes an
empty directories.
link allows the same file to appear under two or more names, often in different
directories for allowing several members of the same programming team to share a
common file, with each of them having the file appear in his own directory, possibly under
different names.
By executing the mount system call, the USB file system can be attached to the root file
system
The mount call makes it possible to integrate removable media into a single integrated file
hierarchy, without having to worry about which device a file is on
Window’s program are event driven. An event occurs that calls the procedure to handle it.
Windows functioning is most driven by GUI based interactions like mouse movement.
There are system calls which are exclusively present windows to deal with GUI and many
of the systems calls which are present in UNIX are missing here.
Following are some of it:
CreateProcess: Creates a new process in Win32
WaitForSingleObject: Waits for a process to exit
ExitProcess: Terminates the execution of process
CreateFile: Opens an existing file or creates a new one
2.5 Operating System
2.5.1 Monolithic System
In the monolithic approach the entire operating system runs as a single program in kernel
mode
The operating system is written as a collection of procedures, linked together into a single
large executable program.
Each procedure in the system is free to call any other process
Being able to call any procedure makes the system very efficient
No information hiding —every procedure is visible to every other procedure
Eg MS DOS and LINUX
This organization suggests a basic structure for the operating system:
Main Function- invokes requested service procedure
Service Procedures- carry out system calls
Utility functions- Help service procedures to perform certain tasks
Disadvantage:
Difficult and complicated structure
A crash in any of these procedures will take down the entire operating system
The operating system is organized as a hierarchy of layers, each one constructed upon the
one below it.The first system constructed in this way was the THE system. The same
concept of layered approach was also implemented by MULTICS with concentric rings.
The procedures in out rings are supposed to make a system call to access the process in
the inner ring
The diagram reflects the structure of The operating system with following details
Layer 0 dealt with allocation of the processor, switching between processes when
interrupts occurred or timers expired.
Layer 1 did the memory management. It allocated space for processes in main memory
Layer 2 handled communication between each process and the operator console
Layer 3 took care of managing the I/O devices and buffering the information streams
Layer 4 was where the user programs were found.
Layer 5 : The system operator process was located.
TRAP instruction whose parameters were carefully checked for validity before the call was
allowed to proceed.
2.5.3 Microkernels
Microkernel structure focusses on making the kernel smaller by reducing the non
essential components from the kernel. These non essential components are placed in user
space
The basic idea behind the microkernel design is to achieve high reliability by splitting the
operating system up into small, well-defined modules
the microkernel—runs in kernel mode
The main function of microkernel is to provide a communication facility between the
client program and various services that are also running in user space
All new services are added to the user space and the kernel don’t need to be modified
Microkernel provides high security and reliability as most of the services are running in
user space , if a service fails the rest operating system remains untouched
Disadvantage :
Performance decrease due to increased system function overhead
The servers, each of which provides some service, and the clients, which use these
services. This model is known as the client-server model.
Since clients communicate with servers by sending messages, the clients need not know
whether the messages are handled locally on their own machines, or whether they are
sent across a network to servers on a remote machine.
As far as the client is concerned,: requests are sent and replies come back.
Thus the client-server model is an abstraction that can be used for a single machine or for
a network of machines
2.5.5 Exokernel
Exokernel runs in the bottom layer of kernel mode.
Its job is to allocate resources to virtual machines and then check attempts to use them to
make sure no machine is trying to use somebody else’s resources.
The advantage of the exokernel scheme is that it saves a layer of mapping whereas the
virtual machine monitor must maintain tables to remap disk addresses
The exokernel need only to keep track of which virtual machine
has been assigned which resource
2.5 Let us Sum Up
1. Different types of operating systems are used in different types of machines depending
upon the need of the user. Some of it are mainframe operating system, server operating
system, embedded operating system, handheld operating system
2. System calls explains what the operating system does. Different types of system calls are
used in operating system activities like file management, process creation, directory
management.
3. The structure of the operating system has evolved with time. Most common ones includes
monolithic, layered, microkernel etc
2.7 Bibliography
Operating System concepts, Eighth edition, Silberschatz, Galvin Gagne
2.8 Unit End Exercise
CHAPTER 3
3.0 Objectives
3.1 Introduction
3.2 Process
3.2.1 Process Creation
3.2.2 Process Termination
3.2.3 Process State
3.3 Threads
3.3.1 Thread Usage
3.3.2 Classical Thread Model
3.3.3 Implementing thread in User Space
3.4.4 Implementing thread in Kernel Space
3.4.5 Hybrid Implementation
3.4 Interprocess Communication
3.4.1 Race Condition
3.4.2 Critical Region
3.4.3 Mutual Exclusion and busy waiting
3.4.4 Sleep and Wake up
3.4.5 Semaphores
3.4.6 Mutex
3.5 Scheduling
3.5.1 First Come First Serve Scheduling
3.5.2 Shortest Job First Scheduling
3.5.3 Priority Scheduling
3.5.4 Round Robin Scheduling
3.5.5 Multiple Queue
3.6 Classical IPC problem
3.6.1 Dinning Philosopher
3.6.2 Reader Writer
3.7 Let us Sum Up
3.8 List of Reference
3.9 Bibliography
3.10 Unit End Exercise
1.0 Objectives
The objective of the chapter is as follow
To understand process and thread and its importance in operating system.
To understand various concepts related to process like scheduling, termination, creation
To understand interprocess communication in process
3.4 Introduction
The most important concept of any operating system is process which is an abstraction of a running
program.
They support the ability to perform concurrent operation even with single processor
Modern computing exists only because of process.
Operating system can make the computer more productive by switching the CPU between processes
3.2 Process
Definition : Process is a program in execution
A running process are organized into sequential processes. Every process needs CPU for
completing its execution. CPU switches back and forth between these running processes
In any multiprogramming system, the CPU switches from process to process quickly, running
each for tens or hundreds of milliseconds
A process is an activity of some kind. It has a program, input, output, and a state.
A single processor may be shared among several processes, with some scheduling algorithm
being accustomed to determine when to stop work on one process and service a different
one. In contrast, a program is something that may be stored on disk, not doing anything
Process memory is divided into four sections:
The text section comprises the compiled program code, read in from non-volatile storage
when the program is launched.
The data section stores global and static variables, allocated and initialized prior to executing
main.
The heap is used for dynamic memory allocation, and is managed via calls to new, delete,
malloc, free, etc.
The stack is used for local variables
Fatal exit:
A termination of a process occurs when it discovers a fatal error.
For example, if a user types the command
cc xyz.c
to compile the program xyz.c and if no such file exists, the compiler simply announces this
fact and exits.
Killed by another process:
A process executes a system call to kill some other process.
In UNIX this call is called as kill. The corresponding Win32 function is TerminateProcess.
Figure 3.1
Reference : “Operating System Concepts” by Abraham Silberschatz, Greg Gagne, and Peter Baer
Galvin
Process model makes it easier to understand what is going on inside the system. Some of the
processes run programs that carry out commands typed in by a user other processes are part of the
system processes.
When a disk interrupt occurs, the system makes a decision to stop running the current process and
run the disk process, which was blocked waiting for that interrupt.
Any process in the system is present in any one of the given states
A thread is a basic unit of CPU utilization, consisting of a program counter, a stack, and a set
of registers.
A process have a single thread of control – There is one program counter, and one sequence
of instructions that can be carried out at any given time
Decomposing an application into multiple sequential threads that run in quasi-parallel, the
programming model becomes simpler
Thread has an ability to share an address space and all of its data among themselves. This
ability is essential for certain applications.
Threads are lighter weight than processes, they are faster to create and destroy than
processes.
A process contains a number of resources such as address space, open files, accounting
information, etc.
In addition to these resources, a process has a thread of control, e.g., program counter,
register contents, stack.
The idea of threads is to permit multiple threads of control to execute within one process.
This is often called multithreading and threads are also known as lightweight processes.
Since threads in the same process share state and stack so switching between them is much
less expensive than switching between separate processes.
Individual threads within the same process are not completely independent but are
cooperating and all are from the same process.
The shared resources makes it easier between threads to use each other resources
A new thread in the same process is created by a library routine like thread_create; similarly
thread_exit terminatea a thread.
Figure 3.2
3.3.4 Implementing thread in User Kernel
Kernel manages the thread by keeping a track of all threads by maintaining a thread table in the
system.
When a thread wants to create a new thread or destroy an existing thread, it makes a kernel call,
which then does the creation or destruction by updating the kernel thread table.
The kernel’s thread table holds each thread’s registers, state, and other information and also
maintains the traditional process table to keep track of processes
Advantages:
Thread-create and friends are now systems and hence much slower.
A thread that blocks causes no particular problem. The kernel can run another thread from this
process or can run another process.
Similarly a page fault in one thread does not automatically block the other threads in the process.
Disadvantages:
Relatively greater cost of creating and destroying threads in the kernel
When a signal comes in then which thread should handle it is a problem
Figure 3.4
3.4.5 Hybrid implementation
Hybrid implementation combines the advantages of userlevel threads with kernel-level threads. One
way is use kernel-level threads and then multiplex user-level threads onto some or all of them.
This model provides maximum flexibility
The kernel is aware of only the kernel-level threads and schedules those.
These user-level threads are created, destroyed, and scheduled like the user-level threads in a
process that runs on an operating system without multithreading capability
Figure 3.4
Figure 3.5
1. In the above example, file name is entered in the special spooler directory for printing.
2. he printer daemon prints the files and then removes their names from the directory.
3. Imagine that our spooler directory has a very large number of slots, numbered 0, 1, 2, …,
each one capable of holding a file name.
4. two shared variables,
5. in – variable pointing to next free slot
6. out – variable pointing to next file to be printed.
7. Process A reads in and stores the value, 7, next free slot. Just then a clock interrupt occurs
and the CPU decides that process switches to process B.
8. Process B also reads in and gets a 7 in local variable next free slot.
9. Process B now continues to run. It stores the name of its file in slot 7 and Then it goes off
and does other things.
10. Eventually, process A runs again, starting from the place it left off.
11. It looks at next free slot, finds a 7 there, and writes its file name in slot 7, erasing the name
that process B just put there.
To suspend the producers when the buffer is full, to suspend the consumers when the buffer is
empty, and to make sure that only one process at a time manipulates a buffer so there are no race
conditions.
Two processes share a common, fixed-size (bounded) buffer. The producer puts information into
the buffer and the consumer takes information out.
Problem arises if the following scenario comes across:
The producer wants to put a new data in the buffer, but buffer is already full.
Solution: Producer goes to sleep and to be awakened when the consumer has removed data.
The consumer wants to remove data from the buffer but buffer is already empty.
Solution: Consumer goes to sleep until the producer puts some data in buffer and wakes consumer
up.
Conclusion
This approaches also leads to same race conditions we have seen in earlier approaches. Race
condition can occur due to the fact that access to ‘count’ is unconstrained. The essence of the
problem is that a wakeup call, sent to a process that is not sleeping, is lost.
3.4.5 Semaphore
E. W. Dijkstra (1965) suggest semaphore, an integer variable to count the number of wakeups
saved for future use. A semaphore could have the value 0, indicating that no wakeups were saved,
or some positive value if one or more wakeups were pending.
Two operations are performed on semaphores called as down(sleep) and up(wakeup).
Processes to synchronize their activities.
These operations are also known as: wait() denoted by P and signal() is denoted by V.
wait(S)
{
while (S <= 0)
;
S--;
}
signal(S)
{
S++;
}
3.4.6 Mutex
Mutex is a simplified version of the semaphore used for managing mutual exclusion of
shared resources.
They are easy and efficient to implement and useful in thread packages that are
implemented entirely in user space.
A mutex is a shared variable that can be in one of two states: unlocked or
Locked.
The semaphore is initialized to the number of resources available.
Each process that wishes to use a resource performs a wait() operation on the semaphore.
When a process releases a resource, it performs a signal() operation.
When the count for the semaphore goes to 0, all resources are being used.
Any processes that wish to use a resource will block until the count becomes greater than
0.
3.5 Scheduling
The part of the operating system that makes the choice is called the scheduler, and the
algorithm it uses is called the scheduling algorithm
Processes are of two types Compute bound or Input output bound
Compute-bound processes have long CPU bursts and infrequent I/O waits
I/O-bound processes have short CPU bursts and frequent I/O waits.
The length of the CPU burst is an important factor
It takes the same time to issue the hardware request to read a disk block no
matter how much or how little time it takes to process the data after they arrive.
Scheduling is of two types preemptive and non preemptive
Scheduling algorithm are classified as Batch, Interactive and Real Time
CPU scheduling takes place when one of the following condition is true
Switching of process from the running state to waiting state
Switching of process from the running state to ready state
Switching of process from the waiting state to ready state
When a process terminates
scheduling under conditions 1 and 4 is called as non-preemptive scheduling.
scheduling under conditions 2 and 3 is preemptive scheduling
Gantt chart:
Gantt chart:
Time quantum = 4
Gantt chart:
average waiting time: (6+4+7)/3 = 5.67
UNIT 2
CHAPTER 4
Memory Management
Objectives:-
1.1 Introduction:
We showed how the CPU can be shared by a set of processes. As a result of CPU scheduling, we
can improve both the utilization of the CPU and the speed of the computer’s response to its
users. To realize this increase in performance, however, we must keep several processes in
memory— that is, we must share memory. In this chapter, we discuss various ways to manage
memory. The memory management algorithms vary from a primitive bare-machine approach to
paging and segmentation strategies. Each approach has its own advantages and disadvantages.
Selection of a memory-management method for a specific system depends on many factors,
especially on the hardware design of the system. As we shall see, many algorithms require
hardware support, leading many systems to have closely integrated hardware and operating-
system memory management.
1.2Address Space:
An address space defines a range of discrete addresses, each of which may correspond to
a network host, peripheral device, disk sector, a memory cell or other logical or physical entity.
For software programs to save and retrieve stored data, each unit of data must have an address
where it can be individually located or else the program will be unable to find and manipulate the
data. The number of address spaces available will depend on the underlying address structure
and these will usually be limited by the computer architecture being used.
1.2.1 Logical Versus Physical Address Space
An address generated by the CPU is commonly referred to as a logical address,whereas an
address seen by the memory unit—that is, the one loaded into the memory-address register of the
memory—is commonly referred to as a physical address.
Another common feature of address spaces are mappings and translations, often forming
numerous layers. This usually means that some higher-level address must be translated to lower-
level ones in some way. For example, file system on a logical disk operates linear sector
numbers, which have to be translated to absolute LBA sector addresses, in simple cases,
via addition of the partition's first sector address. Then, for a disk drive connected via Parallel
ATA, each of them must be converted to logical cylinder-head-sector address due to the
interface historical shortcomings. It is converted back to LBA by the disk controller then, finally,
to physical cylinder, head and sector numbers.
Fig: Illustration of translation from logical block addressing to physical geometry
The Domain Name System maps its names to (and from) network-specific addresses (usually IP
addresses), which in turn may be mapped to link layer network addresses via Address Resolution
Protocol. Also, network address translation may occur on the edge of different IP spaces, such as
a local area network and the Internet.
An iconic example of virtual-to-physical address translation is virtual memory, where
different pages of virtual address space map either to page file or to main memory physical
address space. It is possible that several numerically different virtual addresses all refer to one
physical address and hence to the same physical byte of RAM. It is also possible that a single
virtual address maps to zero, one, or more than one physical address.
Fig: Illustration of translation from virtual address space to physical address space.
The operating system takes care of mapping the logical addresses to physical addresses at the
time of memory allocation to the program. There are three types of addresses used in a program
before and after memory is allocated −
1
Symbolic addresses
The addresses used in a source code. The variable names, constants, and instruction labels are
the basic elements of the symbolic address space.
2
Relative addresses
At the time of compilation, a compiler converts symbolic addresses into relative addresses.
3
Physical addresses
The loader generates these addresses at the time when a program is loaded into main memory.
An addressing scheme whereby reference to an address is made by some convenient symbol that
(preferably) has some relationship to the meaning of the data expected to be located at that
address. It serves as an aid to the programmer. The symbolic address is replaced by some form of
computable/computed address during the operation of an assembler or compiler.
is the technique of addressing instructions and data areas by designating their location in relation
to the location counter or to some symbolic location. This type of addressing is always in
bytes—never in bits, words, or instructions. Thus, the expression *+4 specifies an address that is
4 bytes greater than the current value of the location counter. In the sequence of instructions in
the following example, the location of the CR machine instruction can be expressed in two
ways, ALPHA+2, or BETA-4, because all the machine instructions in the example are for 2 byte
instructions.
identifies a physical location of required data in a memory. The user never directly deals with the
physical address but can access by its corresponding logical address. The user program generates
the logical address and thinks that the program is running in this logical address but the program
needs physical memory for its execution, therefore, the logical address must be mapped to the
physical address by MMU before they are used. The term Physical Address Space is used for all
physical addresses corresponding to the logical addresses in a Logical address space.
Visibility User can view the logical address of User can never view physical address
a program. of program.
Generation generated by the CPU Computed by MMU
Access The user can use the logical address The user can indirectly access physical
to access the physical address. address but not directly.
The memory-management algorithms outlined in Chapter 8 are necessary because of one basic
requirement: The instructions being executed must be the entire logical address space in physical
memory. Dynamic loading can help to ease this restriction, but it generally requires special
precautions and extra
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.
The main visible advantage of this scheme is that programs can be larger than physical memory.
Virtual memory serves two purposes. First, it allows us to extend the use of physical memory
by using disk. Second, it allows us to have memory protection, because each virtual address is
translated to a physical address.
Following are the situations, when entire program is not required to be loaded fully in main
memory.
User written error handling routines are used only when an error occurred in the data or
computation.
Certain options and features of a program may be used rarely.
Many tables are assigned a fixed amount of address space even though only a small
amount of the table is actually used.
The ability to execute a program that is only partially in memory would counter many
benefits.
Less number of I/O would be needed to load or swap each user program into memory.
A program would no longer be constrained by the amount of physical memory that is
available.
Each user program could take less physical memory, more programs could be run the
same time, with a corresponding increase in CPU utilization and throughput.
Modern microprocessors intended for general-purpose use, a memory management unit, or
MMU, is built into the hardware. The MMU's job is to translate virtual addresses into physical
addresses. A basic example is given below −
Virtual memory is commonly implemented by demand paging. It can also be implemented in a
segmentation system. Demand segmentation can also be used to provide virtual memory.
Virtual memory involves the separation of logical memory as perceived by users from physical
memory. This separation allows an extremely large virtual memoryto be provided for
programmerswhenonly a smaller physicalmemory is available .Virtual memory makes the task of
programming much easier, because the programmer no longer needs to worry about the amount
of physical memory available; she can concentrate instead on the problem to be programmed.
A demand paging system is quite similar to a paging system with swapping where processes
reside in secondary memory and pages are loaded only on demand, not in advance. When a
context switch occurs, the operating system does not copy any of the old program’s pages out to
the disk or any of the new program’s pages into the main memory Instead, it just begins
executing the new program after loading the first page and fetches that program’s pages as they
are referenced.
While executing a program, if the program references a page which is not available in the main
memory because it was swapped out a little ago, the processor treats this invalid memory
reference as a page fault and transfers control from the program to the operating system to
demand the page back into the memory.
Advantages
Following are the advantages of Demand Paging −
Disadvantages
Number of tables and the amount of processor overhead for handling page interrupts are
greater than in the case of the simple paged management techniques.
1.3.4 Page Replacement Algorithm
Page replacement algorithms are the techniques using which an Operating System decides
which memory pages to swap out, write to disk when a page of memory needs to be allocated.
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,
An optimal page-replacement algorithm has the lowest page-fault rate of all algorithms.
An optimal page-replacement algorithm exists, and has been called OPT or MIN.
Replace the page that will not be used for the longest period of time. Use the time when a
page is to be used.
1.3.6 Least Recently Used (LRU) algorithm
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.
The page with the smallest count is the one which will be selected for replacement.
This algorithm suffers from the situation in which a page is used heavily during the
initial phase of a process, but then is never used again.
This algorithm is based on the argument that the page with the smallest count was
probably just brought in and has yet to be used
UNIT 2
Chapter 5
Objectives:
Relocation
Protection
Sharing
Sometimes distinct processes may need to execute the same process (e.g.,
many users executing same editor), or even the same data (when one process
prepares data for another process).
When different processes signal or wait the same semaphore, they need to
access the same memory address.
OS has to allow sharing, while at the same time ensure protection.
If memory was segmented then it would be possible to code programs and sub-
routines separately, each with its own degree of protection.
The MM would manage inter-segment references at run-time, and could allow a
segment to be accessed by many different processes.
Paging and segmentation are processes by which data is stored to, then retrieved from,
a computer's storage disk.
Managing computer memory is a basic operating system function -- both paging and
segmentation are basic functions of the OS. No system can efficiently rely on limited
RAM alone. So the computer’s memory management unit (MMU) uses the storage
disk, HDD or SSD, as virtual memory to supplement RAM.
2.1 What is Paging?
As mentioned above, the memory management function called paging specifies storage
locations to the CPU as additional memory, called virtual memory. The CPU cannot
directly access storage disk, so the MMU emulates memory by mapping pages to
frames that are in RAM.
Before we launch into a more detailed explanation of pages and frames, let’s define
some technical terms.
Physical memory: The computer’s random access memory (RAM), typically contained
in DIMM cards attached to the computer’s motherboard.
Virtual address: The CPU generates a virtual address for each active process. The
MMU maps the virtual address to a physical location in RAM and passes the address to
the bus. A virtual address space is the range of virtual addresses under CPU control.
Physical address: The physical address is a location in RAM. The physical address
space is the set of all physical addresses corresponding to the CPU’s virtual addresses.
A physical address space is the range of physical addresses under MMU control.
2.0 Fig: Paging concept
By assigning an address to a piece of data using a "page table" between the CPU and
the computer's physical memory, a computer's MMU enables the system to retrieve that
data whenever needed.
The MMU uses page tables to translate virtual addresses to physical ones. Each table
entry indicates where a page is located: in RAM or on disk as virtual memory. Tables
may have a single or multi-level page table such as different tables for applications and
segments.
However, constant table lookups can slow down the MMU. A memory cache called the
Translation Lookaside Buffer (TLB) stores recent translations of virtual to physical
addresses for rapid retrieval. Many systems have multiple TLBs, which may reside at
different locations, including between the CPU and RAM, or between multiple page
table levels.
Different frame sizes are available for data sets with larger or smaller pages and
matching-sized frames. 4KB to 2MB are common sizes, and GB-sized frames are
available in high-performance servers.
The main idea behind the paging is to divide each process in the form of pages. The
main memory will also be divided in the form of frames.
One page of the process is to be stored in one of the frames of the memory. The pages
can be stored at the different locations of the memory but the priority is always to find
the contiguous frames or holes.
Pages of the process are brought into the main memory only when they are required
otherwise they reside in the secondary storage.
Different operating system defines different frame sizes. The sizes of each frame must
be equal. Considering the fact that the pages are mapped to the frames in Paging, page
size needs to be as same as frame size.
2.1A fig: Paging process
Example
Let us consider the main memory size 16 Kb and Frame size is 1 KB therefore the main
memory will be divided into the collection of 16 frames of 1 KB each.
There are 4 processes in the system that is P1, P2, P3 and P4 of 4 KB each. Each
process is divided into pages of 1 KB each so that one page can be stored in one
frame.
Initially, all the frames are empty therefore pages of the processes will get stored in the
contiguous way.
Frames, pages and the mapping between the two is shown in the image below.
2.1 B fig: Paging process
Let us consider that, P2 and P4 are moved to waiting state after some time. Now, 8
frames become empty and therefore other pages can be loaded in that empty place.
The process P5 of size 8 KB (8 pages) is waiting inside the ready queue.
Given the fact that, we have 8 non contiguous frames available in the memory and
paging provides the flexibility of storing the process at the different places. Therefore,
we can load the pages of process P5 in the place of P2 and P4.
2.1 C fig: Paging process
The Working Set Model. In the purest form of paging, processes are started up with
none of their pages in memory. ...
Local versus Global Allocation Policies. In the preceding sections we have discussed
several algorithms for choosing a page to replace when a fault occurs. ...
Page Size. ...
Virtual Memory Interface.
3.0 Segmentation
The details about each segment are stored in a table called as segment table. Segment
table is stored in one (or many) of the segments.
Till now, we were using Paging as our main memory management technique. Paging is
more close to Operating system rather than the User. It divides all the process into the
form of pages regardless of the fact that a process can have some relative parts of
functions which needs to be loaded in the same page.
Operating system doesn't care about the User's view of the process. It may divide the
same function into different pages and those pages may or may not be loaded at the
same time into the memory. It decreases the efficiency of the system.
It is better to have segmentation which divides the process into the segments. Each
segment contain same type of functions such as main function can be included in one
segment and the library functions can be included in the other segment,
1. Segment Number
2. Offset
The Segment number is mapped to the segment table. The limit of the respective
segment is compared with the offset. If the offset is less than the limit then the address
is valid otherwise it throws an error as the address is invalid.
In the case of valid address, the base address of the segment is added to the offset to
get the physical address of actual word in the main memory.
3.0 Fig : Segmentation
Advantages of Segmentation
1. No internal fragmentation
2. Average Segment Size is larger than the actual page size.
3. Less overhead
4. It is easier to relocate segments than entire address space.
5. The segment table is of lesser size as compare to the page table in paging.
Disadvantages
1. It can have external fragmentation.
2. it is difficult to allocate contiguous memory to variable sized partition.
3. Costly memory management algorithms.
Difference between Paging and Segmentation:
S.NO PAGING SEGMENTATION
In paging, program is
split into page number and Here, logical address is split into
In an operating system that uses paging for memory management, a page replacement
algorithm is needed to decide which page needs to be replaced when new page comes
in.
Page Fault – A page fault happens when a running program accesses a memory page
that is mapped into the virtual address space, but not loaded in physical memory.
Since actual physical memory is much smaller than virtual memory, page faults happen.
In case of page fault, Operating System might have to replace one of the existing pages
with the newly needed page. Different page replacement algorithms suggest different
ways to decide which page to replace. The target for all algorithms is to reduce the
number of page faults.
Page Replacement Algorithms :
This is the simplest page replacement algorithm. In this algorithm, the operating
system keeps track of all pages in the memory in a queue, the oldest page is in the
front of the queue. When a page needs to be replaced page in the front of the queue
is selected for removal.
Example-1Consider page reference string 1, 3, 0, 3, 5, 6 with 3 page frames.Find
number of page faults.
Initially all slots are empty, so when 1, 3, 0 came they are allocated to the empty
slots —> 3 Page Faults.
when 3 comes, it is already in memory so —> 0 Page Faults.
Then 5 comes, it is not available in memory so it replaces the oldest page slot i.e 1.
—>1 Page Fault.
6 comes, it is also not available in memory so it replaces the oldest page slot i.e 3 —
>1 Page Fault.
Finally when 3 come it is not avilable so it replaces 0 1 page fault
In this algorithm, pages are replaced which would not be used for the longest
duration of time in the future.
Example-2:Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, with 4
page frame. Find number of page fault.
Initially all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4
Page faults
0 is already there so —> 0 Page fault.
when 3 came it will take the place of 7 because it is not used for the longest duration
of time in the future.—>1 Page fault.
0 is already there so —> 0 Page fault..
4 will takes place of 1 —> 1 Page Fault.
Now for the further page reference string —> 0 Page fault because they are already
available in the memory.
Optimal page replacement is perfect, but not possible in practice as the operating
system cannot know future requests. The use of Optimal Page replacement is to set
up a benchmark so that other replacement algorithms can be analyzed against it.
Initially all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4
Page faults
0 is already their so —> 0 Page fault.
when 3 came it will take the place of 7 because it is least recently used —>1 Page
fault
0 is already in memory so —> 0 Page fault.
4 will takes place of 1 —> 1 Page Fault
Now for the further page reference string —> 0 Page fault because they are already
available in the memory.
UNIT 2
Chapter 6
File System
Objectives:
Files
Directories
file system implementation
file-system management and optimization
MS-DOS file system
UNIX V7 file system
CDROM file system
1.0 File
A File Structure should be according to a required format that the operating system can
understand.
A file has a certain defined structure according to its type.
A text file is a sequence of characters organized into lines.
A source file is a sequence of procedures and functions.
An object file is a sequence of bytes organized into blocks that are
understandable by the machine.
When operating system defines different file structures, it also contains the code
to support these file structure. Unix, MS-DOS support minimum number of file
structure.
File type 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 −
1)Ordinary files
2)Directory files
These files contain list of file names and other information related to these files.
3)Special files
File access mechanism refers to the manner in which the records of a file may be
accessed. There are several ways to access files −
Sequential access
Direct/Random access
Indexed sequential access
1)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.
2)Direct/Random access
Files are allocated disk spaces by operating system. Operating systems deploy
following three main ways to allocate disk space to files.
Contiguous Allocation
Linked Allocation
Indexed Allocation
1)Contiguous Allocation
2)Linked Allocation
3)Indexed Allocation
A directory is a container that is used to contain folders and file. It organizes files and
folders into a hierarchical manner.
There are several logical structures of a directory, these are given below.
1. Single-level directory –
Single level directory is simplest directory structure.In it all files are contained in
same directory which make it easy to support and understand.
A single level directory has a significant limitation, however, when the number of files
increases or when the system has more than one user. Since all the files are in the
same directory, they must have the unique name . if two users call their dataset test,
then the unique name rule violated.
Advantages:
Since it is a single directory, so its implementation is very easy.
If the files are smaller in size, searching will become faster.
The operations like file creation, searching, deletion, updating are very easy
in such a directory structure.
Disadvantages:
There may chance of name collision because two files can not have the same
name.
Searching will become time taking if the directory is large.
In this can not group the same type of files together.
2. Two-level directory –
As we have seen, a single level directory often leads to confusion of files names
among different users. the solution to this problem is to create a separate directory
for each user.
In the two-level directory structure, each user has there own user files directory
(UFD). The UFDs has similar structures, but each lists only the files of a single user.
system’s master file directory (MFD) is searches whenever a new user id=s logged
in. The MFD is indexed by username or account number, and each entry points to
the UFD for that user.
Advantages:
We can give full path like /User-name/directory-name/.
Different users can have same directory as well as file name.
Searching of files become more easy due to path name and user-grouping.
Disadvantages:
3. Tree-structured directory –
Once we have seen a two-level directory as a tree of height 2, the natural
generalization is to extend the directory structure to a tree of arbitrary height.
This generalization allows the user to create there own subdirectories and to
organize on their files accordingly.
A tree structure is the most common directory structure. The tree has a root
directory, and every file in the system have a unique path.
Advantages:
Very generalize, since full path name can be given.
Very scalable, the probability of name collision is less.
Searching becomes very easy, we can use both absolute path as well as
relative.
Disadvantages:
Every file does not fit into the hierarchical model, files may be saved into
multiple directories.
We can not share files.
It is inefficient, because accessing a file may go under multiple directories.
Advantages:
We can share files.
Searching is easy due to different-different paths.
Disadvantages:
We share the files via linking, in case of deleting it may create the problem,
If the link is softlink then after deleting the file we left with a dangling pointer.
In case of hardlink, to delete a file we have to delete all the reference
associated with it.
Advantages:
It allows cycles.
It is more flexible than other directories structure.
Disadvantages:
It is more costly than others.
It needs garbage collection.
A file is a collection of related information. The file system resides on secondary storage
and provides efficient and convenient access to the disk by allowing data to be stored,
located, and retrieved.
File system organized in many layers :
I/O Control level –
Device drivers acts as interface between devices and Os, they help to transfer data
between disk and main memory. It takes block number a input and as output it
gives low level hardware specific instruction.
/li>
Basic file system –
It Issues general commands to device driver to read and write physical blocks on
disk.It manages the memory buffers and caches. A block in buffer can hold the
contents of the disk block and cache stores frequently used file system metadata.
File organization Module –
It has information about files, location of files and their logical and physical
blocks.Physical blocks do not match with logical numbers of logical block
numbered from 0 to N. It also has a free space which tracks unallocated blocks.
Logical file system –
It manages metadata information about a file i.e includes all details about a file
except the actual contents of file. It also maintains via file control blocks. File
control block (FCB) has information about a file – owner, size, permissions,
location of file contents.
Advantages :
2. In-Memory Structure :
They are maintained in main-memory and these are helpful for file system management
for caching. Several in-memory structures given below :
1) Mount Table –
It contains information about each mounted volume.
2) Directory-Structure cache –
This cache holds the directory information of recently accessed
directories.
3) System wide open-file table –
It contains the copy of FCB of each open file.
4) Per-process open-file table –
It contains information opened by that particular process and it maps with
appropriate system wide open-file.
3)Directory Implementation :
1)Linear List –
It maintains a linear list of filenames with pointers to the data blocks.It is time-
consuming also.To create a new file, we must first search the directory to be
sure that no existing file has the same name then we add a file at end of the
directory.To delete a file, we search the directory for the named file and
release the space.To reuse the directory entry either we can mark the entry
as unused or we can attach it to a list of free directories.
2)Hash Table –
The hash table takes a value computed from the file name and returns a
pointer to the file. It decreases the directory search time. The insertion and
deletion process of files is easy. The major difficulty is hash tables are its
generally fixed size and hash tables are dependent on hash function on that
size.
1)Disk-Space Management
Since all the files are normally stored on disk one of the main concerns of
file system is management of disk space.
2)Block Size
The main question that arises while storing files in a fixed-size blocks is
the size of the block. If the block is too large space gets wasted and if the
block is too small time gets waste. So, to choose a correct block size
some information about the file-size distribution is required. Performance
and space-utilization are always in conflict.
3)Keeping track of free blocks
After a block size has been finalized the next issue that needs to be
catered is how to keep track of the free blocks. In order to keep track there
are two methods that are widely used:
Using a linked list: Using a linked list of disk blocks with each
block holding as many free disk block numbers as will fit.
5)File-system Backups
There are two ways for dumping a disk to the backup disk:
The above figure depicts a popular algorithm used in many UNIX systems
wherein squares depict directories and circles depict files. This algorith
dumps all the files and directories that have been modified and also the
ones on the path to a modified file or directory. The dump algorithm
maintains a bitmap indexed by i-node number with several bits per i-node.
Bits will be set and cleared in this map as the algorithm proceeds.
Although logical dumping is straightforward, there are few issues
associated with it.
Since the free block list is not a file, it is not dumped and
hence it must be reconstructed from scratch after all the
dumps have been restored
Special files, named pipes and all other files that are not real
should never be dumped.
6)File-system Consistency
7)File-system Performance
Since the access to disk is much slower than access to memory, many file
systems have been designed with various optimizations to improve
performance as described below.
8)Caching
The most common technique used to reduce disk access time is the block
cache or buffer cache. Cache can be defined as a collection of items of
the same type stored in a hidden or inaccessible place. The most common
algorithm for cache works in such a way that if a disk access is initiated,
the cache is checked first to see if the disk block is present. If yes then the
read request can be satisfied without a disk access else the disk block is
copied to cache first and then the read request is processed.
Due to continuous creation and removal of files the disks get badly
fragmented with files and holes all over the place. As a consequence,
when a new file is created, the blocks used for it may be spread all over
the disk, giving poor performance. The performance can be restored by
moving files around to make them contiguous and to put all (or at least
most) of the free space in one or more large contiguous regions on the
disk.
In MS-DOS, every DOS based partition has a letter: (A: or B: or C:). Typically, the drive
letters A: and B: are reserved for floppy drives. You will most frequently find that the C:
drive is the 'bootable partition'. Each drive has a root directory ('\') so the root directory
on a given drive looks like this: C:\
A:> C: <enter>
C:>
MS-DOS then stores files to the system in any arrangement you choose. You can
create directories, and store files within those directories. A typical file/path might look
like this:
C:\ms-dos\mydir\filename.txt
LIMITATIONS
FAT16 filesystems are compatible with all Microsoft operating systems, but it has
severe limitations. First, all files on the system are limited to eight characters and a
three letter extension. The MS-DOS filesystem also has a limit of approximately 2.1
Gigabytes owing to the fact that the MS-DOS operating system doesn't recognize 'Int
13' based commands, and therefore cannot issue commands to access the remainder
of larger disks.
Keep in mind that MS-DOS is a legacy system kept around for doing command line
based work in Windows.
6.0 Unix File System
Unix file system is a logical method of organizing and storing large amounts of information in a
way that makes it easy to manage. A file is a smallest unit in which the information is stored. Unix
file system has several important features. All data in Unix is organized into files. All files are
organized into directories. These directories are organized into a tree-like structure called the file
system.
Files in Unix System are organized into multi-level hierarchy structure known as a directory tree.
At the very top of the file system is a directory called “root” which is represented by a “/”. All
other files are “descendants” of root.
1. Ordinary files – An ordinary file is a file on the system that contains data, text, or program
instructions.
Used to store your information, such as some text you have written or an image you have drawn.
This is the type of file that you usually work with.
Always located within/under a directory file.
Do not contain other files.
In long-format output of ls -l, this type of file is specified by the “-” symbol.
2. Directories – Directories store both special and ordinary files. For users familiar with Windows
or Mac OS, UNIX directories are equivalent to folders. A directory file contains an entry for every
file and subdirectory that it houses. If you have 10 files in a directory, there will be 10 entries in the
directory. Each entry has two components.
(1) The Filename
(2) A unique identification number for the file or directory (called the inode number)
Branching points in the hierarchical tree.
Never contain “real” information which you would work with (such as text). Basically, just used
for organizing files.
All files are descendants of the root directory, ( named / ) located at the top of the tree.
3. Special Files – Used to represent a real physical device such as a printer, tape drive or terminal,
used for Input/Output (I/O) operations. Device or special files are used for device
Input/Output(I/O) on UNIX and Linux systems. They appear in a file system just like an ordinary
file or a directory.
On UNIX systems there are two flavors of special files for each device, character special files and
block special files :
When a character special file is used for device Input/Output(I/O), data is transferred one character
at a time. This type of access is called raw device access.
When a block special file is used for device Input/Output(I/O), data is transferred in large fixed-size
blocks. This type of access is called block device access.
For terminal devices, it’s one character at a time. For disk devices though, raw access means
reading or writing in whole chunks of data – blocks, which are native to your disk.
In long-format output of ls -l, character special files are marked by the “c” symbol.
In long-format output of ls -l, block special files are marked by the “b” symbol.
4. Pipes – UNIX allows you to link commands together using a pipe. The pipe acts a temporary
file which only exists to hold data from one command until it is read by another.A Unix pipe
provides a one-way flow of data.The output or result of the first command sequence is used as the
input to the second command sequence. To make a pipe, put a vertical bar (|) on the command line
between two commands.For example: who | wc -l
7.0 What is CDFS (Compact Disc File System)?
Introduction:
CDFS stands for Compact Disc File System. Before the era of CDFS, there was no
medium for people to store their memories or files that they want to store for the long term
purpose. The storing of data and information was a major problem because in that time
the world needs a system that can store multiple files in compressed format. But the
revolution of technology changed the culture of the world and new advanced things
started coming to the market. CDFS came into the picture on 21 August 1999. At that
time CDFS is considered the most advanced technology in the technology Industry.
There were many features offered by CDFS that came into limelight immediately:
1. It is a file system for read-only and write-once CD-ROMs.
2. It exports all tracks and boot images on a CD as normal files.
3. CDFS provides a wide range of services which include creation, replacing,
renaming, or deletion of files on write-once media.
4. It uses a VCACHE driver to control the CD-ROM disc cache allowing for a
smoother playback.
5. It includes several disc properties like volume attributes, file attributes, and file
placement.
History:
CDFS was developed by Simson Garfinkel and J. Spencer Love at the MIT Media Lab
between 1985 and 1986. CDFS was developed from the write-once CD-ROM simulator.
They are designed to store any data and information on read-only and write-once media.
A great setback for CDFS was that it never gets sold. The File System source code was
published on the internet.
Disk Images can be saved using the CDFS standard, which may be used to burn ISO
9660 discs. ISO 9660 also referred to as CDFS by some hardware and software
providers, is a file system published by ISO (International Organization for
Standardization) for optical disc media.
Applications:
A file system is a systematic organized way in which files have to get organized in a hard
disk. The file system is initiated when a user opens a hard disk to access files. Here are
some applications of the Compact Disk File System:
1. CDFS creates a way in which the system first sets up the root directory and then
automatically creates all the subsequent folders for it.
2. The system also provides a wide range of services for all users. You can create
new files or folders which are added to the main root file or we can say the “file
tree” of the system.
3. There was also a problem of transferring data or files from CDs to a laptop or
computer. But CDFS shows us a great solution to solve this problem. It is useful for
burning discs that can be exchanged between different devices.
4. CDFS is not specific to a single Operating System, it means that a disc burned on
Macintosh using CDFS can be read on a Windows or Linux based computer.
5. It can operate over numerous Operating System. It means if a user started shifting
files from Macintosh using Compact Disk File System, he can also operate the files
in Windows Operating System.
6. Disc Pictures are also saved using proper system standards. All files have a
typical.ISO name extension.
Types:
There are different versions of Compact Disk File System:
1. Clustered operated system. (can be Global or Grid)
2. Flash operated
3. Object file system
4. Semantic
5. Steganographic process
6. Versioning
7. Synthetic operated system
UNIT 3
Chapter no 7
Principles of I/O hardware and Software
7.0 Objectives:
Some DMA controllers can also operate in either mode. In the former mode, the
DMA controller requests the transfer of one word and gets it. If the CPU also wants
the bus, it has to wait. The mechanism is called cycle stealing because the device
controller sneaks in and steals an occasional bus cycle from the CPU once in a
while, delaying it slightly.
In block mode, the DMA controller tells the device to acquire the bus, issue a series
of transfers, then release the bus. This form of operation is called burst mode. It is
more efficient than cycle stealing because acquiring the bus takes time and multiple
words can be transferred for the price of one bus acquisition. The down side to burst
mode is that it can block the CPU and other devices for a substantial period if a long
burst is being transferred.
If no other interrupts are pending, the interrupt controller handles the interrupt
immediately. However, if another interrupt is in progress, or another device has
made a simultaneous request on a higher-priority interrupt request line on the bus,
the device is just ignored for the moment. In this case it continues to assert an
interrupt signal on the bus until it is serviced by the CPU. To handle the interrupt, the
controller puts a number on the address lines specifying which device wants
attention and asserts a signal to interrupt the CPU. The interrupt signal causes the
CPU to stop what it is doing and start doing something else. The number on the
address lines is used as an index into a table called the interrupt vector to fetch a
new program counter. This program counter points to the start of the corresponding
interrupt-service procedure.
Precise Interrupts
An interrupt that leaves the machine in a well-defined state is called a precise
interrupt.
Such an interrupt has four properties:
1. The PC (Program Counter) is saved in a known place.
2. All instructions before the one pointed to by the PC have completed.
3. No instruction beyond the one pointed to by the PC has finished.
4. The execution state of the instruction pointed to by the PC is known.
7.2 PRINCIPLES OF I/O SOFTWARE
First we will look at its goals and then at the different ways I/O can be done from the
point of view of the operating system.
7.2.1 Goals of the I/O Software
A key concept in the design of I/O software is known as device independence.
What it means is that we should be able to write programs that can access any I/O
device without having to specify the device in advance. For example, a program that
reads a file as input should be able to read a file on a hard disk, a DVD, or on a USB
stick without having to be modified for each different device.
It is up to the operating system to take care of the problems caused by the fact that
these devices really are different and require very different command sequences to
read or write.
Another important issue for I/O software is error handling. In general, errors should
be handled as close to the hardware as possible. If the controller discovers a read
error, it should try to correct the error itself if it can.
Still another important issue is that of synchronous (blocking) vs. asynchronous
(interrupt-driven) transfers. Most physical I/O is asynchronous—the CPU starts the
transfer and goes off to do something else until the interrupt arrives. User programs
are much easier to write if the I/O operations are blocking—after a read system call
the program is automatically suspended until the data are available in the buffer. It is
up to the operating system to make operations that are actually interrupt-driven look
blocking to the user programs.
The final concept that we will mention here is sharable vs. dedicated devices. Some
I/O devices, such as disks, can be used by many users at the same time. No
problems are caused by multiple users having open files on the same disk at the
same time. Other devices, such as printers, have to be dedicated to a single user
until that user is finished. Then another user can have the printer.
7.2.2 Programmed I/O
The simplest form of I/O is to have the CPU do all the work. This method is called
programmed I/O.
It is simplest to illustrate how programmed I/O works by means of an example.
Consider a user process that wants to print the eight-character string ‘‘ABCDEFGH’’
on the printer via a serial interface. Displays on small embedded systems sometimes
work this way. The software first assembles the string in a buffer in user space, as
shown in Fig. 7.4
The user process then acquires the printer for writing by making a system call to
open it. If the printer is currently in use by another process, this call will fail and
return an error code or will block until the printer is available, depending on the
operating system and the parameters of the call. Once it has the printer, the user
process makes a system call telling the operating system to print the string on the
printer.
The operating system then (usually) copies the buffer with the string to an array, say,
p, in kernel space, where it is more easily accessed (because the kernel may have to
change the memory map to get at user space). It then checks to see if the printer is
currently available. If not, it waits until it is. As soon as the printer is available, the
operating system copies the first character to the printer’s data register, in this
example using memory-mapped I/O. This action activates the printer. The character
may not appear yet because some printers buffer a line or a page before printing
anything. In Fig. 7.4 (b), however, we see that the first character has been printed
and that the system has marked the ‘‘B’’ as the next character to be printed. As soon
as it has copied the first character to the printer, the operating system checks to see
if the printer is ready to accept another one. Generally, the printer has a second
register, which gives its status. The act of writing to the data register causes the
status to become not ready. When the printer controller has processed the current
character, it indicates its availability by setting some bit in its status register or putting
some value in it.
At this point the operating system waits for the printer to become ready again.
When that happens, it prints the next character, as shown in Fig. 7.4 (c). This loop
continues until the entire string has been printed. Then control returns to the user
process.
The basic function of the device-independent software is to perform the I/O functions
that are common to all devices and to provide a uniform interface to the user-level
software. We will now look at the above issues in more detail.
Buffering
Buffering is also an issue, both for block and character devices, for a variety of
reasons. To see one of them, consider a process that wants to read data from an
(ADSL—Asymmetric Digital Subscriber Line) modem, something many people use at
home to connect to the Internet. One possible strategy for dealing with the incoming
characters is to have the user process do a read system call and block waiting for
one character. Each arriving character causes an interrupt. The interrupt-service
procedure hands the character to the user process and unblocks it. After putting the
character somewhere, the process reads another character and blocks again.
Error Reporting
Errors are far more common in the context of I/O than in other contexts. When they
occur, the operating system must handle them as best it can. Many errors are device
specific and must be handled by the appropriate driver, but the framework for error
handling is device independent.
One class of I/O errors is programming errors. These occur when a process asks for
something impossible, such as writing to an input device (keyboard, scanner, mouse,
etc.) or reading from an output device (printer, plotter, etc.). Other errors are
providing an invalid buffer address or other parameter, and specifying an invalid
device (e.g., disk 3 when the system has only two disks), and so on. The action to
take on these errors is straightforward: just report back an error code to the caller.
Another class of errors is the class of actual I/O errors, for example, trying to write a
disk block that has been damaged or trying to read from a camcorder that has been
switched off. In these circumstances, it is up to the driver to determine what to do. If
the driver does not know what to do, it may pass the problem back up to device-
independent software.
What this software does depends on the environment and the nature of the error. If it
is a simple read error and there is an interactive user available, it may display a
dialog box asking the user what to do. The options may include retrying a certain
number of times, ignoring the error, or killing the calling process. If there is no user
available, probably the only real option is to have the system call fail with an error
code.
Exercise 7.4
Q.1) What is the use of Boot Block?
Q.2) What is Sector Sparing?
Q.3) Explain Direct Memory Access?
Q.4) Explain Programmed I/O in details.
Q.5) Explain Device-Independent I/O Software.
UNIT 3
Chapter 8
I/O Devices
8.0 Objectives:
To understand the Disk concept
To learn CLOCKS Concept
To learn different, USER INTERFACES
To understand THIN CLIENTS and Power management
In addition to providing abstractions such as processes, address spaces, and files,
an operating system also controls all the computer’s I/O (Input/Output) devices. It
must issue commands to the devices, catch interrupts, and handle errors. It should
also provide an interface between the devices and the rest of the system that is
simple and easy to use. To the extent possible, the interface should be the same for
all devices (device independence). The I/O code represents a significant fraction of
the total operating system. How the operating system manages I/O is the subject of
this chapter.
This chapter is organized as follows. We will look first at some of the principles of I/O
hardware and then at I/O software in general. I/O software can be structured in
layers, with each having a well-defined task. We will look at these layers to see what
they do and how they fit together. Next, we will look at several I/O devices in detail:
disks, clocks, keyboards, and displays. For each device we will look at its hardware
and software. Finally, we will consider power management.
8.1 DISKS
We will begin with disks, which are conceptually simple, yet very important. After that
we will examine clocks, keyboards, and displays.
8.1.1 Disk Hardware
Disks come in a variety of types. The most common ones are the magnetic hard
disks. They are characterized by the fact that reads and writes are equally fast,
which makes them suitable as secondary memory (paging, file systems, etc.). Arrays
of these disks are sometimes used to provide highly reliable storage. For distribution
of programs, data, and movies, optical disks (DVDs and Blu-ray) are also important.
Finally, solid-state disks are increasingly popular as they are fast and do not contain
moving parts. In the following sections we will discuss magnetic disks as an example
of the hardware and then describe the software for disk devices in general.
Magnetic Disks
Magnetic disks are organized into cylinders, each one containing as many tracks as
there are heads stacked vertically. The tracks are divided into sectors, with the
number of sectors around the circumference typically being 8 to 32 on floppy disks,
and up to several hundred on hard disks. The number of heads varies from 1 to
about 16.
Older disks have little electronics and just deliver a simple serial bit stream. On these
disks, the controller does most of the work. On other disks, in particular, IDE
(Integrated Drive Electronics) and SATA (Serial ATA) disks, the disk drive itself
contains a microcontroller that does considerable work and allows the real controller
to issue a set of higher-level commands. The controller often does track caching,
bad-block remapping, and much more.
A device feature that has important implications for the disk driver is the possibility
of a controller doing seeks on two or more drives at the same time. These are known
as overlapped seeks. While the controller and software are waiting for a seek to
complete on one drive, the controller can initiate a seek on another drive. Many
controllers can also read or write on one drive while seeking on one or more other
drives, but a floppy disk controller cannot read or write on two drives at the same
time. (Reading or writing requires the controller to move bits on a microsecond time
scale, so one transfer uses up most of its computing power.) The situation is different
for hard disks with integrated controllers, and in a system with more than one of
these hard drives they can operate simultaneously, at least to the extent of
transferring between the disk and the controller’s buffer memory. Only one transfer
between the controller and the main memory is possible at once, however. The
ability to perform two or more operations at the same time can reduce the average
access time considerably.
Figure 8.1 compares parameters of the standard storage medium for the original IBM
PC with parameters of a disk made three decades later to show how much disks
changed in that time. It is interesting to note that not all parameters have improved
as much. Average seek time is almost 9 times better than it was, transfer rate is
16,000 times better, while capacity is up by a factor of 800,000. This pattern has to
do with relatively gradual improvements in the moving parts, but much higher bit
densities on the recording surfaces.
One thing to be aware of in looking at the specifications of modern hard disks is that
the geometry specified, and used by the driver software, is almost always different
from the physical format. On old disks, the number of sectors per track was the same
for all cylinders. Modern disks are divided into zones with more sectors on the outer
zones than the inner ones.
RAID
CPU performance has been increasing exponentially over the past decade, roughly
doubling every 18 months. Not so with disk performance. In the 1970s, average seek
times on minicomputer disks were 50 to 100 msec. Now seek times are still a few
msec. In most technical industries (say, automobiles or aviation), a factor of 5 to 10
performance improvement in two decades would be major news (imagine 300-MPG
cars), but in the computer industry it is an embarrassment.
Thus the gap between CPU performance and (hard) disk performance has become
much larger over time. Can anything be done to help?
Fig 8.2
The preamble starts with a certain bit pattern that allows the hardware to recognize
the start of the sector. It also contains the cylinder and sector numbers and some
other information. The size of the data portion is determined by the low level
formatting program. Most disks use 512-byte sectors. The ECC field contains
redundant information that can be used to recover from read errors. The size and
content of this field varies from manufacturer to manufacturer, depending on how
much disk space the designer is willing to give up for higher reliability and how
complex an ECC code the controller can handle. A 16-byte ECC field is not unusual.
Furthermore, all hard disks have some number of spare sectors allocated to be used
to replace sectors with a manufacturing defect.
The position of sector 0 on each track is offset from the previous track when the low-
level format is laid down. This offset, called cylinder skew, is done to improve
performance. The idea is to allow the disk to read multiple tracks in one continuous
operation without losing data.
8.1.3 Disk Arm Scheduling Algorithms
In this section we will look at some issues related to disk drivers in general.
First, consider how long it takes to read or write a disk block. The time required is
determined by three factors:
1. Seek time (the time to move the arm to the proper cylinder).
2. Rotational delay (how long for the proper sector to appear under the reading
head).
3. Actual data transfer time.
For most disks, the seek time dominates the other two times, so reducing the mean
seek time can improve system performance substantially.
If the disk driver accepts requests one at a time and carries them out in that order,
that is, FCFS (First-Come, First-Served), little can be done to optimize seek time.
However, another strategy is possible when the disk is heavily loaded. It is likely that
while the arm is seeking on behalf of one request, other disk requests may be
generated by other processes. Many disk drivers maintain a table, indexed by
cylinder number, with all the pending requests for each cylinder chained together
in a linked list headed by the table entries.
Given this kind of data structure, we can improve upon the first-come, first served
scheduling algorithm. To see how, consider an imaginary disk with 40 cylinders.
A request comes in to read a block on cylinder 11. While the seek to cylinder 11 is in
progress, new requests come in for cylinders 1, 36, 16, 34, 9, and 12, in that order.
They are entered into the table of pending requests, with a separate linked list for
each cylinder. The requests are shown in Fig. 8.3 . When the current request (for
cylinder 11) is finished, the disk driver has a choice of which request to handle next.
Using FCFS, it would go next to cylinder 1, then to 36, and so on. This algorithm
would require arm motions of 10, 35, 20, 18, 25, and 3, respectively, for a total of
111 cylinders.
Fig 8.3
There are two general approaches to bad blocks: deal with them in the controller or
deal with them in the operating system. In the former approach, before the disk is
shipped from the factory, it is tested and a list of bad sectors is written onto the disk.
For each bad sector, one of the spares is substituted for it.
There are two ways to do this substitution. In Fig. 8.4 (a) we see a single disk track
with 30 data sectors and two spares. Sector 7 is defective. What the controller can
do is remap one of the spares as sector 7 as shown in Fig. 8.4(b). The other way is
to shift all the sectors up one, as shown in Fig. 8.4 (c). In both cases the controller
has to know which sector is which. It can keep track of this information through
internal tables (one per track) or by rewriting the preambles to give the remapped
sector numbers. If the preambles are rewritten, the method of Fig. 8.4(c) is more
work (because 23 preambles must be rewritten) but ultimately gives better
performance because an entire track can still be read in one rotation.
Fig 8.4
Errors can also develop during normal operation after the drive has been installed.
The first line of defense upon getting an error that the ECC cannot handle is to just
try the read again. Some read errors are transient, that is, are caused by specks of
dust under the head and will go away on a second attempt. If the controller notices
that it is getting repeated errors on a certain sector, it can switch to a spare before
the sector has died completely. In this way, no data are lost and the operating
system and user do not even notice the problem. Usually, the method of Fig. 8.4(b)
has to be used since the other sectors might now contain data. Using the method of
Fig. 8.4(c) would require not only rewriting the preambles, but copying all the data as
well.
8.1.5 Stable Storage
As we have seen, disks sometimes make errors. Good sectors can suddenly
become bad sectors. Whole drives can die unexpectedly. RAIDs protect against a
few sectors going bad or even a drive falling out. However, they do not protect
against write errors laying down bad data in the first place. They also do not protect
against crashes during writes corrupting the original data without replacing them by
newer data.
For some applications, it is essential that data never be lost or corrupted, even in the
face of disk and CPU errors. Ideally, a disk should simply work all the time with no
errors. Unfortunately, that is not achievable. What is achievable is a disk subsystem
that has the following property: when a write is issued to it, the disk either correctly
writes the data or it does nothing, leaving the existing data intact.
Such a system is called stable storage and is implemented in software (Lampson
and Sturgis, 1979). The goal is to keep the disk consistent at all costs. Below we will
describe a slight variant of the original idea.
Before describing the algorithm, it is important to have a clear model of the possible
errors. The model assumes that when a disk writes a block (one or more sectors),
either the write is correct or it is incorrect and this error can be detected on a
subsequent read by examining the values of the ECC fields. In principle, guaranteed
error detection is never possible because with a, say, 16-byte ECC field guarding a
512-byte sector, there are 24096 data values and only 2144 ECC values. Thus if a
block is garbled during writing but the ECC is not, there are billions upon billions of
incorrect combinations that yield the same ECC. If any of them occur, the error will
not be detected. On the whole, the probability of random data having the proper 16-
byte ECC is about 2−144, which is small enough that we will call it zero, even though
it is really not.
The model also assumes that a correctly written sector can spontaneously go bad
and become unreadable. However, the assumption is that such events are so rare
that having the same sector go bad on a second (independent) drive during a
reasonable time interval (e.g., 1 day) is small enough to ignore.
The model also assumes the CPU can fail, in which case it just stops. Any disk write
in progress at the moment of failure also stops, leading to incorrect data in one
sector and an incorrect ECC that can later be detected. Under all these conditions,
stable storage can be made 100% reliable in the sense of writes either working
correctly or leaving the old data in place. Of course, it does not protect against
physical disasters, such as an earthquake happening and the computer falling 100
meters into a fissure and landing in a pool of boiling magma. It is tough to recover
from this condition in software.
Stable storage uses a pair of identical disks with the corresponding blocks working
together to form one error-free block. In the absence of errors, the corresponding
blocks on both drives are the same. Either one can be read to get the same result.
To achieve this goal, the following three operations are defined:
1. Stable writes. A stable write consists of first writing the block on drive 1, then
reading it back to verify that it was written correctly. If it was not, the write and reread
are done again up to n times until they work. After n consecutive failures, the block is
remapped onto a spare and the operation repeated until it succeeds, no matter how
many spares have to be tried. After the write to drive 1 has succeeded, the
corresponding block on drive 2 is written and reread, repeatedly if need be, until it,
too, finally succeeds. In the absence of CPU crashes, when a stable write
completes, the block has correctly been written onto both drives and verified on both
of them.
2. Stable reads. A stable read first reads the block from drive 1. If this yields an
incorrect ECC, the read is tried again, up to n times. If all of these give bad ECCs,
the corresponding block is read from drive 2. Given the fact that a successful stable
write leaves two good copies of the block behind, and our assumption that the
probability of the same block spontaneously going bad on both drives in a
reasonable time interval is negligible, a stable read always succeeds.
3. Crash recovery. After a crash, a recovery program scans both disks comparing
corresponding blocks. If a pair of blocks are both good and the same, nothing is
done. If one of them has an ECC error, the bad block is overwritten with the
corresponding good block. If a pair of blocks are both good but different, the block
from drive 1 is written onto drive 2.
In the absence of CPU crashes, this scheme always works because stable writes
always write two valid copies of every block and spontaneous errors are assumed
never to occur on both corresponding blocks at the same time. What about in the
presence of CPU crashes during stable writes? It depends on precisely when the
crash occurs. There are five possibilities, as depicted in Fig. 8.5
Fig 8.5
8.2 CLOCKS
Clocks (also called timers) are essential to the operation of any multiprogrammed
system for a variety of reasons. They maintain the time of day and prevent one
process from monopolizing the CPU, among other things. The clock software can
take the form of a device driver, even though a clock is neither a block device, like a
disk, nor a character device, like a mouse. Our examination of clocks will follow the
same pattern as in the previous section: first a look at clock hardware and then a
look at the clock software.
8.2.1 Clock Hardware
Two types of clocks are commonly used in computers, and both are quite different
from the clocks and watches used by people. The simpler clocks are tied to the 110-
or 220-volt power line and cause an interrupt on every voltage cycle, at 50 or 60 Hz.
These clocks used to dominate, but are rare nowadays.
When a piece of quartz crystal is properly cut and mounted under tension, it can be
made to generate a periodic signal of very great accuracy, typically in the range of
several hundred megahertz to a few gigahertz, depending on the crystal chosen.
Using electronics, this base signal can be multiplied by a small integer to get
frequencies up to several gigahertz or even more. At least one such circuit is usually
found in any computer, providing a synchronizing signal to the computer’s various
circuits. This signal is fed into the counter to make it count down to zero. When the
counter gets to zero, it causes a CPU interrupt.
Programmable clocks typically have several modes of operation. In one-shot mode,
when the clock is started, it copies the value of the holding register into the counter
and then decrements the counter at each pulse from the crystal. When the counter
gets to zero, it causes an interrupt and stops until it is explicitly started again by the
software. In square-wave mode, after getting to zero and causing the interrupt, the
holding register is automatically copied into the counter, and the whole process is
repeated again indefinitely. These periodic interrupts are called clock ticks.
8.2.2 Clock Software
All the clock hardware does is generate interrupts at known intervals. Everything else
involving time must be done by the software, the clock driver. The exact duties of the
clock driver vary among operating systems, but usually include most of the following:
1. Maintaining the time of day.
2. Preventing processes from running longer than they are allowed to.
3. Accounting for CPU usage.
4. Handling the alar m system call made by user processes.
5. Providing watchdog timers for parts of the system itself.
6. Doing profiling, monitoring, and statistics gathering.
The first clock function, maintaining the time of day (also called the real time) is not
difficult.
8.3 USER INTERFACES: KEYBOARD, MOUSE, MONITOR
Every general-purpose computer has a keyboard and monitor (and sometimes a
mouse) to allow people to interact with it. Although the keyboard and monitor are
technically separate devices, they work closely together. On mainframes, there are
frequently many remote users, each with a device containing a keyboard and an
attached display as a unit. These devices have historically been called terminals.
People frequently still use that term, even when discussing personal computer
keyboards and monitors (mostly for lack of a better term).
8.3.1 Input Software
User input comes primarily from the keyboard and mouse (or somtimes touch
screens), so let us look at those. On a personal computer, the keyboard contains an
embedded microprocessor which usually communicates through a specialized serial
port with a controller chip on the parentboard (although increasingly keyboards are
connected to a USB port). An interrupt is generated whenever a key is struck and a
second one is generated whenever a key is released. At each of these keyboard
interrupts, the keyboard driver extracts the information about what happens from the
I/O port associated with the keyboard. Everything else happens in software and is
pretty much independent of the hardware.
Most of the rest of this section can be best understood when thinking of typing
commands to a shell window (command-line interface). This is how programmers
commonly work. We will discuss graphical interfaces below. Some devices, in
particular touch screens, are used for input and output. We hav e made an (arbitrary)
choice to discuss them in the section on output devices. We will discuss graphical
interfaces later in this chapter.
Keyboard Software
The number in the I/O register is the key number, called the scan code, not the
ASCII code. Normal keyboards have fewer than 128 keys, so only 7 bits are needed
to represent the key number. The eighth bit is set to 0 on a key press and to 1 on a
key release. It is up to the driver to keep track of the status of each key (up or down).
So all the hardware does is give press and release interrupts. Software does the
rest.
When the A key is struck, for example, the scan code (30) is put in an I/O register. It
is up to the driver to determine whether it is lowercase, uppercase, CTRLA, ALT-A,
CTRL-ALT-A, or some other combination. Since the driver can tell which keys hav e
been struck but not yet released (e.g., SHIFT), it has enough information to do the
job.
For example, the key sequence DEPRESS SHIFT, DEPRESS A, RELEASE A,
RELEASE SHIFT indicates an uppercase A. However, the key sequence DEPRESS
SHIFT, DEPRESS A, RELEASE SHIFT, RELEASE A also indicates an uppercase A.
Although this keyboard interface puts the full burden on the software, it is extremely
flexible. For example, user programs may be interested in whether a digit just typed
came from the top row of keys or the numeric keypad on the side. In principle, the
driver can provide this information.
Two possible philosophies can be adopted for the driver. In the first one, the driver’s
job is just to accept input and pass it upward unmodified. A program reading from the
keyboard gets a raw sequence of ASCII codes. (Giving user programs the scan
codes is too primitive, as well as being highly keyboard dependent.) This philosophy
is well suited to the needs of sophisticated screen editors such as emacs, which
allow the user to bind an arbitrary action to any character or sequence of characters.
It does, however, mean that if the user types dste instead of date and then corrects
the error by typing three backspaces and ate, followed by a carriage return, the user
program will be given all 11 ASCII codes typed, as follows:
d s t e←←←a t e CR
Not all programs want this much detail. Often they just want the corrected input, not
the exact sequence of how it was produced. This observation leads to the second
philosophy: the driver handles all the intraline editing and just delivers corrected lines
to the user programs. The first philosophy is character oriented; the second one is
line oriented. Originally they were referred to as raw mode and cooked mode,
respectively.
Mouse Software
Most PCs have a mouse, or sometimes a trackball, which is just a mouse lying on its
back. One common type of mouse has a rubber ball inside that protrudes through a
hole in the bottom and rotates as the mouse is moved over a rough surface. As the
ball rotates, it rubs against rubber rollers placed on orthogonal shafts. Motion in the
east-west direction causes the shaft parallel to the y-axis to rotate; motion in the
north-south direction causes the shaft parallel to the x-axis to rotate. Another popular
type is the optical mouse, which is equipped with one or more light-emitting diodes
and photodetectors on the bottom. Early ones had to operate on a special mousepad
with a rectangular grid etched onto it so the mouse could count lines crossed.
Modern optical mice have an image-processing chip in them and make continuous
low-resolution photos of the surface under them, looking for changes from image to
image. Whenever a mouse has moved a certain minimum distance in either direction
or a button is depressed or released, a message is sent to the computer. The
minimum distance is about 0.1 mm (although it can be set in software). Some people
call this unit a mickey. Mice (or occasionally, mouses) can have one, two, or three
buttons, depending on the designers’ estimate of the users’ intellectual ability to keep
track of more than one button. Some mice have wheels that can send additional data
back to the computer. Wireless mice are the same as wired mice except that instead
of sending their data back to the computer over a wire, they use low-power radios,
for example, using the Bluetooth standard.
Chapter 9
Deadlocks
9.0 Objectives:
A deadlock occurs when every member of a set of processes is waiting for an event
that can only be caused by a member of the set.
1. A has obtained ownership of the printer and will release it after printing one file.
2. B has obtained ownership of the tape drive and will release it after reading one
file.
3. A tries to get ownership of the tape drive, but is told to wait for B to release it.
4. B tries to get ownership of the printer, but is told to wait for A to release the
printer.
9.1 Resources
To repeat: A deadlock occurs when a every member of a set of processes is waiting for
an event that can only be caused by a member of the set.
The following four conditions (Coffman; Havender) are necessary but not sufficient for
deadlock. Repeat: They are not sufficient.
The first three are characteristics of the system and resources. That is, for a given
system with a fixed set of resources, the first three conditions are either true or false:
They don't change with time. The truth or falsehood of the last condition does indeed
change with time as the resources are requested/allocated/released.
For example if each PC deadlocks once per 100 years, the one reboot may be
less painful that the restrictions needed to prevent it.
Consider the case in which there is only one instance of each resource.
In this case the 4 necessary conditions for deadlock are also sufficient.
So the problem comes down to finding a directed cycle in the resource allocation
graph. Why?
Answer: Because the other three conditions are either satisfied by the system we
are studying or are not in which case deadlock is not a question. That is,
conditions 1,2,3 are conditions on the system in general not on what is
happening right now.
To find a directed cycle in a directed graph is not hard. The idea is simple.
1. For each node in the graph do a depth first traversal to see if the graph is a DAG
(directed acyclic graph), building a list as you go down the DAG (and pruning it
as you backtrack back up).
2. If you ever find the same node twice on your list, you have found a directed
cycle, the graph is not a DAG, and deadlock exists among the processes in your
current list.
3. If you never find the same node twice, the graph is a DAG and no deadlock
occurs.
4. The searches are finite since there are a finite number of nodes.
The figure on the above shows a resource allocation graph with multiple unit
resources.
Request edges are drawn to the box since they represent a request for any dot in
the box.
Allocation edges are drawn from the dot to represent that this unit of the resource
has been assigned (but all units of a resource are equivalent and the choice of
which one to assign is arbitrary).
Note that there is a directed cycle in red, but there is no deadlock. Indeed the
middle process might finish, erasing the green arc and permitting the blue dot to
satisfy the rightmost process.
An algorithm for detecting deadlocks in this more general setting. The idea is as
follows.
1. look for a process that might be able to terminate (i.e., all its request arcs
can be satisfied).
2. If one is found pretend that it does terminate (erase all its arcs), and
repeat step 1.
3. If any processes remain, they are deadlocked.
The algorithm just given makes the most optimistic assumption about a running
process: it will return all its resources and terminate normally. If we still find
processes that remain blocked, they are deadlocked.
Preemption
In some cases it may be possible to temporarily take a resource away from its current
owner and give it to another process.
Perhaps you can temporarily preempt a resource from a process. Not likely.
For example, to take a laser printer away from its owner, the operator can collect all the
sheets already printed and put them in a pile. Then the process can be suspended
(marked as not runnable). At this point the printer can be assigned to another process.
When that process finishes, the pile of printed sheets can be put back in the printer’s
output tray and the original process restarted.
Rollback
If the system designers and machine operators know that deadlocks are likely, they can
arrange to have processes checkpointed periodically. Checkpointing a process means
that its state is written to a file so that it can be restarted later
Database (and other) systems take periodic checkpoints. If the system does take
checkpoints, one can roll back to a checkpoint whenever a deadlock is detected.
Somehow must guarantee forward progress.
Kill processes
The crudest but simplest way to break a deadlock is to kill one or more processes. One
possibility is to kill a process in the cycle. With a little luck, the other processes will be
able to continue. If this does not help, it can be repeated until the cycle is broken.
Can always be done but might be painful. For example some processes have had
effects that can't be simply undone. Print, launch a missile, etc.
In the discussion of deadlock detection, we tacitly assumed that when a process asks
for resources, it asks for them all at once (Figure 9.3 R Matrix ). In most systems,
however, resources are requested one at a time. The system must be able to decide
whether granting a resource is safe or not and make the allocation only when it is safe.
Thus, the question arises: Is there an algorithm that can always avoid deadlock by
making the right choice all the time? The answer is a qualified yes—we can avoid
deadlocks, but only if certain information is available in advance.
We plot progress of each process along an axis. In the example we show, there are two
processes, hence two axes, i.e., planar. This procedure assumes that we know the
entire request and release pattern of the processes in advance so it is not a practical
solution. I present it as it is some motivation for the practical solution that follows, the
Banker's Algorithm.
Not surprisingly, the resource manager knows how many units of each resource
it had to begin with.
Also it knows how many units of each resource it has given to each process.
It would be great to see all the programs in advance and thus know all future
requests, but that is asking for too much.
Instead, when each process starts, it announces its maximum usage. That is
each process, before making any resource requests, tells the resource manager
the maximum number of units of each resource the process can possible need.
This is called the claim of the process.
o If the claim is greater than the total number of units in the system the
resource manager kills the process when receiving the claim (or returns
an error code so that the process can make a new claim).
o If during the run the process asks for more than its claim, the process is
aborted (or an error code is returned and no resources are allocated).
o If a process claims more than it needs, the result is that the resource
manager will be more conservative than need be and there will be more
waiting.
Definition: A state is safe if there is an ordering of the processes such that: if the
processes are run in this order, they will all terminate (assuming none exceeds its
claim).
Recall the comparison made above between detecting deadlocks (with multi-unit
resources) and the banker's algorithm
The deadlock detection algorithm given makes the most optimistic assumption
about a running process: it will return all its resources and terminate normally. If
we still find processes that remain blocked, they are deadlocked.
The banker's algorithm makes the most pessimistic assumption about a running
process: it immediately asks for all the resources it can (details later on “can”). If,
even with such demanding processes, the resource manager can assure that all
process terminates, then we can assure that deadlock is avoided.
In the definition of a safe state no assumption is made about the running processes;
that is, for a state to be safe termination must occur no matter what the processes do
(providing the all terminate and to not exceed their claims). Making no assumption is the
same as making the most pessimistic assumption.
You can NOT tell until I give you the initial claims of the process.
Please do not make the unfortunately common exam mistake to give an example
involving safe states without giving the claims.
Since the manager know all the claims, it can determine the maximum amount of
additional resources each process can request.
The manager knows how many units of each resource it has left.
The manager then follows the following procedure, which is part of Banker's
Algorithms discovered by Dijkstra, to determine if the state is safe.
2. Seek a process P whose max additional requests is less than what remains (for
each resource type).
o If no such process can be found, then the state is not safe.
o The banker (manager) knows that if it refuses all requests excepts those
from P, then it will be able to satisfy all of P's requests. Why?
Ans: Look at how P was chosen.
3. The banker now pretends that P has terminated (since the banker knows that it
can guarantee this will happen). Hence the banker pretends that all of P's
currently held resources are returned. This makes the banker richer and hence
perhaps a process that was not eligible to be chosen as P previously, can now
be chosen.
Example 1
Require each process to request all resources at the beginning of the run. This is often
called One Shot.
If we can prevent processes that hold resources from waiting for more resources, we
can eliminate deadlocks. One way to achieve this goal is to require all processes to
request all their resources before starting execution. If everything is available, the
process will be allocated whatever it needs and can run to completion. If one or more
resources are busy, nothing will be allocated and the process will just wait.
An immediate problem with this approach is that many processes do not know how
many resources they will need until they hav e started running.
If a process has been assigned the printer and is in the middle of printing its output,
forcibly taking away the printer because a needed plotter is not available is tricky at best
and impossible at worst. However, some resources can be virtualized to avoid this
situation. Spooling printer output to the disk and allowing only the printer daemon
access to the real printer eliminates deadlocks involving the printer, although it creates
a potential for deadlock over disk space. With large disks though, running out of disk
space is unlikely.
The circular wait can be eliminated in several ways. One way is simply to have a rule
saying that a process is entitled only to a single resource at any moment. If it needs a
second one, it must release the first one. For a process that needs to copy a huge file
from a tape to a printer, this restriction is unacceptable. Another way to avoid the
circular wait is to provide a global numbering of all the resources, as shown in Fig. 9.b
Now the rule is this: processes can request resources whenever they want to, but all
requests must be made in numerical order. A process may request first a printer and
then a tape drive, but it may not request first a plotter and then a printer.
9.7: Issues
Although both avoidance and prevention are not terribly promising in the general case,
for specific applications, many excellent special-purpose algorithms are known. As an
example, in many database systems, an operation that occurs frequently is requesting
locks on several records and then updating all the locked records. When multiple
processes are running at the same time, there is a real danger of deadlock. The
approach often used is called two-phase locking.
9.7.2: Starvation
As usual FCFS is a good cure. Often this is done by priority aging and picking the
highest priority process to get the resource. Also can periodically stop accepting new
processes until all old ones get their resources.
Problems on Deadlock:
Problem 01:
A system is having 3 user processes each requiring 2 units of resource R. The minimum
number of units of R such that no deadlock will occur-
1. 3
2. 5
3. 4
4. 6
Solution-
In worst case,
The number of units that each process holds = One less than its maximum demand
So,
Process P1 holds 1 unit of resource R
Process P2 holds 1 unit of resource R
Process P3 holds 1 unit of resource R
Thus,
Maximum number of units of resource R that ensures deadlock = 1 + 1 + 1 = 3
Minimum number of units of resource R that ensures no deadlock = 3 + 1 = 4
Problem-02:
Thus,
Maximum number of units of resource R that ensures deadlock = 1 + 2 + 3 = 6
Minimum number of units of resource R that ensures no deadlock = 6 + 1 = 7
9.8 Exercise
Q. 1) Explain how the system can recover from the deadlock using
Q.10) A system is having 3 user processes P1, P2 and P3 where P1 requires 21 units
of resource R, P2 requires 31 units of resource R, P3 requires 41 units of resource R.
The minimum number of units of R that ensures no deadlock is _____?
UNIT 4:
CHAPTER 10
Virtualization and Cloud
10.0 Objectives
10.1 Introduction
10.1.1 About VMM
10.1.2 Advantages
10.2 Introduction - Cloud
10.3 Requirements for Virtualization
10.4 Type 1 & Type 2 Hypervisors
10.5 Let us sum it up
10.6 List of references
10.7 Bibliography
10.8 Unit end exercise
10.0 Objectives
1. It is important to mention that not all virtualization technology tries to trick the
guest into believing that it has the entire system.
2. Sometimes, the aim is simply to allow a process to run that was originally written
for a different operating system and/or architecture.
3. We therefore distinguish between full system virtualization and process-level
virtualization.
4. In the year 1972, Goldberg distinguished between two approaches of
virtualization.
a) Type 1 Hypervisor: Technically, it is like an operating system, since it is the
only program running in the most privileged mode. Its job is to support
multiple copies of the actual hardware, called virtual machines, similar to the
processes a normal operating system runs.
Fig shows Type 1 Hypervisor
10.7 Bibliography
1. What is Cloud?
2. Explain Virtualization.
3. Explain types of Hypervisor with neat diagrams.
CHAPTER 11
11.0 Objectives
11.1 Pre-requisites
11.2 Techniques for efficient virtualization
11.3 Memory virtualization
11.4 I/O Virtualization
11.5 Virtual appliances
11.6 Let us sum it up
11.7 List of References
11.8 Bibliography
11.9 Unit end exercise
11.0 Objectives
The objectives of this chapter is as follows:
1. The objective of this chapter is make students learn about the different
Virtualization and Cloud technologies.
2. To learn what are the different techniques used for Virtualization.
3. Understand Memory Virtualization as well as I/O Virtualization.
4. The need of Virtual Appliances.
11.1 Pre-requisites
1. VMM creates the illusion of multiple machines on the same physical hardware.
2. Virtualization gives a range of advantages from running different operating
systems to developing software.
3. Outsourcing is the best option for storing data in the data centre.
4. Type 1 and type 2 are the two categories offered by VMM to achieve
virtualization.
1. We have discussed the issue of how to virtualize the CPU so far. But a computer
system has more than just a CPU.
2. It also has memory and I/O devices. They have to be virtualized, too.
3. Let us have a look at how Memory virtualization happens:
a) The boxes represent pages, and the arrows show the different memory
mappings.
b) The arrows from guest virtual memory to guest physical memory show the
mapping maintained by the page tables in the guest operating system.
c) The arrows from guest physical memory to machine memory show the
mapping maintained by the VMM.
d) The dashed arrows show the mapping from guest virtual memory to machine
memory in the shadow page tables also maintained by the VMM.
e) The underlying processor running the virtual machine uses the shadow page
table mappings
4. Modern operating systems nearly all support virtual memory, which is basically a
mapping of pages in the virtual address space onto pages of physical memory.
5. This mapping is defined by (multilevel) page tables. Typically, the mapping is set
in motion by having the operating system set a control register in the CPU that points
to the top-level page table.
6. Virtualization greatly complicates memory management. In fact, it took hardware
manufacturers two tries to get it right.
1. The guest operating system will typically start out probing the hardware to find
out what kinds of I/O devices are attached. These probes will trap to the
hypervisor. Hypervisor will do two things:
2. One approach is for it to report back that the disks, printers, and so on are the
ones that the hardware actually has.
i. The guest will then load device drivers for these devices and try to use
them.
ii. When the device drivers try to do actual I/O, they will read and write the
device‟s hardware device registers.
iii. These instructions are sensitive and will trap to the hypervisor, which could
then copy the needed values to and from the hardware registers, as
needed.
iv. But here, too, we have a problem. Each guest OS could think it owns an
entire disk partition, and there may be many more virtual machines
(hundreds) than there are actual disk partitions.
3. The usual solution is for the hypervisor to create a file or region on the actual disk
for each virtual machine‟s physical disk.
i. Since the guest OS is trying to control a disk that the real hardware has
(and which the hypervisor understands), it can convert the block number
being accessed into an offset into the file or disk region being used for
storage and do the I/O.
ii. It is also possible for the disk that the guest is using to be different from
the real one.
4. Another interesting trend related to I/O is that the hypervisor can take the role of
a virtual switch.
i. In this case, each virtual machine has a MAC address and the hypervisor
switches frames from one virtual machine to another—just like an Ethernet
switch would do.
ii. Virtual switches have several advantages. For instance, it is very easy to
reconfigure them. Also, it is possible to augment the switch with additional
functionality, for instance for additional security.
1. Virtual machines offer a solution to a problem that has long plagued users,
especially users of open source software: how to install new application programs?
2. The problem is that many applications are dependent on numerous other
applications and libraries, which are themselves dependent on a host of other
software packages, and so on.
3. Furthermore, there may be dependencies on particular versions of the compilers,
scripting languages, and the operating system.
4. With virtual machines now available, a software developer can carefully construct
a virtual machine, load it with the required operating system, compilers, libraries, and
application code, and freeze the entire unit, ready to run.
5. This virtual machine image can then be put on a CD-ROM or a Website for
customers to install or download.
6. This approach means that only the software developer has to understand all the
dependencies. The customers get a complete package that actually works,
completely independent of which operating system they are running and which other
software, packages, and libraries they have installed.
7. These „„shrink wrapped‟‟ virtual machines are often called “virtual appliances”.
8. As an example, Amazon‟s EC2 cloud has many pre-packaged virtual appliances
available for clients, which it offers as convenient software services („„Software as a
Service‟‟).
11.8 Bibliography
12.0 Objectives
12.1 Pre-requisites
12.2 Virtual machines on multicore CPUs
12.3 Licensing Issues
12.4 Clouds
12.4.1 Characteristics
12.4.2 Services Offered
12.4.3 Advantages
12.5 Multiple Processor Systems
12.5.1 Multiprocessors
12.5.2 Multi-computers
12.5.3 Distributed Systems
12.6 Let us sum it up
12.7 List of References
12.8 Bibliography
12.9 Unit end Exercise
12.0 Objectives
12.1 Pre-requisites
1. It has never been possible for an application designer to first choose how many
CPUs he wants and then write the software accordingly.
2. The combination of virtual machines and multicore CPUs creates a whole new
world in which the number of CPUs available can be set by the software.
3. This is clearly a new phase in computing. Moreover, virtual machines can share
memory.
4. A typical example where this is useful is a single server hosting multiple
instances of the same operating systems.
5. All that has to be done is map physical pages into the address spaces of multiple
virtual machines.
6. Memory sharing is already available in deduplication solutions. Deduplication
avoids storing the same data twice.
7. It is a common technique in storage systems, but is now appearing in
virtualization as well.
8. In general, the technique revolves around scanning the memory of each of the
virtual machines on a host and hashing the memory pages.
9. Should some pages produce an identical hash, the system has to first check to
see if they really are the same, and if so, de-duplicate them, creating one page
with the actual content and two references to that page. Since the hypervisor
controls the nested (or shadow) page tables, this mapping is straightforward.
10. The combination of multicore, virtual machines, hypervisor, and microkernels is
going to radically change the way people think about computer systems.
11. Current software cannot deal with the idea of the programmer determining how
many CPUs are needed, whether they should be a multicomputer or a
multiprocessor, and how minimal kernels of one kind or another fit into the
picture.
12.4 Clouds
12.5.2 Multi-computers
a. Following are the various inter-connection technologies used in Multi-
computer:
b. Single Switch/ Star topology- Every node contains a network interface
card and all computers are connected to switches/hubs. Fast,
expandable but single point failure systems. Failure in switch/hub can
take down entire system.
c. Ring Topology- Each node has two wires coming out the network
interface card, one into the node on the left and one going into the
node on the right. There is no use of switches in this topology.
d. Grid/mesh topology- two dimensional design with multiple switches and
can be expanded easily to large size. Its diameter is the longest path
between any two nodes.
e. Double Torus- alternative to grid, which is a grid with the edges
connected. With compare to grid its diameter is less and it is more fault
tolerant. The diameter is less as opposite corners communicates in
only two hops.
f. Cube- Fig e. shows 2 x 2 x 2 cube which is a regular three-
dimensional topology. In general case it could be a n x n x n cube. No
of nodes = 2n. So for 3D cube, 8 nodes can be attached.
g. A 4-D Hypercube- Fig (f) shows four –dimensional cube constructed
from two three – dimensional cubes with the equivalent nodes
connected. An n-dimensional cube formed this way is called a
hypercube. Many parallel computers can be building using hypercube
topology.
12.5.3 Distributed Systems:
a. A distributed system is defined as set of autonomous computers that
appears to its users as a single coherent system.
b. Users of distributed system feel that, they are working with as a single
system.
c. Distributed system is like multi-computers spread worldwide.
d. Each node in distributed system is having its own CPU, RAM, network
board. OS, and disk for paging.
e. Following are the main characteristics of distributed systems:
i. A distributed system comprises computers with different
architecture and different OS. These dissimilarities and the ways all
these machines communicate are hidden from users.
ii. The manner in which distributed system is organised is also hidden
from the users of the distributed system.
iii. The interaction of users and applications with distributed system is
in consistent and identical way.
iv. It should be always available to the users and applications in spite
of failures. Failure handling should be hidden from users and
applications.
12.8 Bibliography
Chapter 13
Objectives
13.1 HISTORY
13.2 OVERVIEW
13.8 Summary
13.10 Bibliography
13.11 Questions
13.1 History Of Unix And Linux
13.1.1 History of UNIX
IV. Ken Thompson spent a year's sabbatical with the University of California
at Berkeley. While there he and two graduate students, Bill Joy and Chuck
Haley, wrote the first Berkely version of Unix, which was distributed to
students.
V. This resulted in the source code being worked on and developed by many
different people.
VI. The Berkeley version of Unix is known as BSD, Berkeley Software
Distribution. From BSD came the vi editor, C shell, virtual memory,
Sendmail, and support for TCP/IP.
VII. For several years SVR4 was the more conservative, commercial, and well
supported.
VIII. Today SVR4 and BSD look very much alike. Probably the biggest
cosmetic difference between them is the way the ps command functions.
IX. The Linux operating system was developed as a Unix look alike and has a
user command interface that resembles SVR4.
X. Following figure shows history in better way –
13.1.2 History of Linux
Linux is an open source family of Unix-like Linux based kernel applications, a kernel
operating system that was first released on September 17, 1991, by Linus Torvalds
Linux usually included in the Linux distribution.
Linux was originally designed for computers based on the Intel x86 architecture, but has
since been deployed to more platforms than any other operating system. Linux is a
leading operating system on servers and other large-scale systems such as keyword
computers.
The Unix operating system was developed in 1969 at AT & T Bell Laboratories in
America by Ken Thompson and Dennis Ritchie. Unix's high-performance language
acquisition has made it easy to be deployed across different computer platforms.
Creation
Today the Linux systems are used in throughout computing that is from all the
embedded systems on almost all the supercomputers, and on the server installations
such as the very much popular the LAMP Application Stack. The use of Linux
distribution on home and enterprise desktops is growing. Linux are also popular in the
netbook market, many devices install customized Linux distributions, and Google has
released its own Chrome OS designed for netbooks.
13.2 OVERVIEW
The operating system controls all commands from all keyboards and all data generated,
and allows each user to believe that he or she is the only person working on the
computer.
The real-time sharing of resources makes UNIX one of the most powerful operating
systems ever.
Multitasking capability
Many computers can only do one thing at a time, and anyone with a PC or laptop
can prove it. While opening the browser and opening the word processing program,
try to log in to the company's network. When arranging multiple instructions, the
processor may freeze for a few seconds.
Multiuser capability
The same design that allows multitasking allows multiple users to use the computer.
The computer can accept many user commands (depending on the design of the
computer) to run programs, access files and print documents at the same time.
UNIX programs
UNIX tools - Hundreds of programs come with UNIX, and these programs can be
divided into two categories: Integrated utilities essential for computer operation, such
as command interpreters and Tools that are not required for UNIX operation, but
provide users with additional functions, such as typesetting functions and e-mail.
In addition to the applications that come with UNIX, hundreds of UNIX applications can
be purchased from third-party vendors. Although third-party vendors have written some
tools for specific applications, there are hundreds of tools available for UNIX users.
Generally, tools are divided into categories for certain functions (such as word
processing, business applications, or programming).
Linux is a Unix - like computer OS which is assembled & made under the model of free
and open source software development and distribution. The most defined component
of Linux is the Linux kernel, an OS kernel was first released on 1991 by Linus Torvalds.
• An init program - This is a process launched by the Linux kernel, & is at the root
of the process tree, in other words, all processes are launched through init. It
starts processes such as system services & login prompts (whether graphical or
in terminal mode)
• Software libraries which contain code which can be used by running processes.
On Linux OS using ELF-format executable files, the dynamic linker which
manages use of dynamic libraries is "ld-linux.so".
• The most commonly used software library on Linux systems is the GNU C
Library. If the OS is set up for the user to compile software themselves, header
files will also be included to describe the interface of installed libraries.
Linux is a widely ported operating system kernel. Currently most of the distribution
include a graphical user environment, with the 2 most popular environments which are
GNOME (it basically utilizes additional shells such as the default GNOME Shell &
Ubuntu Unity), & KDE Plasma Desktop
A Linux-based system may be a modular Unix-like OS. It derives much of its basic
design from principles established in Unix during the 1970s and 1980s. Such a system
uses a monolithic kernel, the Linux kernel, which handles process control, networking,
and peripheral and filing system access. Device drivers are either integrated directly
with the kernel or added as modules loaded while the system is running.
The Linux kernel consists of several important parts: process management, memory
management, hardware device drivers, filesystem drivers, network management, and
various other bits and pieces. Memory management takes care of assigning memory
areas and swap file areas to processes, parts of the kernel, and for the buffer cache.
Process management creates processes, and implements multitasking by switching the
active process on the processor. At rock bottom level, the kernel contains a hardware
driver for every quite hardware it supports. There are often many otherwise similar
pieces of hardware that differ in how they're controlled by software. The similarities
make it possible to possess general classes of drivers that support similar operations;
each member of the category has an equivalent interface to the remainder of the kernel
but differs in what it must do to implement them. for instance, all disk drivers look alike
to the remainder of the kernel, i.e., all of them have operations like `initialize the drive',
`read sector N', and `write sector N'. Some software services provided by the kernel
itself have similar properties, and may therefore be abstracted into classes. for instance,
the varied network protocols are abstracted into one programming interface, the BSD
socket library. Another example is that the virtual filesystem (VFS) layer that abstracts
the filesystem operations faraway from their implementation. Each filesystem type
provides an implementation of every filesystem operation. When some entity tries to use
a filesystem, the request goes via the VFS, which routes the request to the right
filesystem driver.
Init the only most vital service during a UNIX is provided by init, init is started because the first
process of each UNIX, because the last item the kernel does when it boots. When init starts,
it continues the boot process by doing various start-up chores (checking and mounting
filesystems, starting daemons, etc). When the system is pack
up, it's init that's responsible of killing all other processes, unmounting all filesystems and
stopping the processor, along side anything it's been configured to try to do
Syslog
The kernel and lots of system programs produce error, warning, and other messages.
it's often important that these messages are often viewed later, even much later, in
order that they should be written to a file. The program doing this is often syslog . It are
often configured to sort the messages to different files consistent with writer or degree
of importance. for instance, kernel messages are often directed to a separate file from
the others, since kernel messages are often more important and wish to be read
regularly to identify problems.
Both users and system administrators often got to run commands periodically. for
instance, the supervisor might want to run a command to wash the directories with
temporary files (/tmp and /var/tmp) from old files, to stay the disks from filling up, since
not all programs pack up after themselves correctly.
The cron service is about up to try to this. Each user can have a crontab file, where she
lists the commands she wishes to execute and therefore the times they ought to be
executed. The cron daemon takes care of starting the commands when specified.
Graphical interface
This arrangement makes the system more flexible, but has the disadvantage that it's
simple to implement a special interface for every program, making the system harder to
find out.
The graphical environment primarily used with Linux is named the X Window System (X
for short). Some popular window managers are: fvwm, icewm, blackbox, and
windowmaker. There also are two popular desktop managers, KDE and Gnome.
Networking
Networking is that the act of connecting two or more computers in order that they will
communicate with one another. the particular methods of connecting and
communicating are slightly complicated, but the top result's very useful.
UNIX operating systems have many networking features. most elementary services
(filesystems, printing, backups, etc) are often done over the network.
Network logins
Network logins work a touch differently than normal logins. for every person logging in
via the network there's a separate virtual network connection, and there are often any
number of those counting on the available bandwidth. it's therefore impossible to run a
separate getty for every possible virtual connection.
UNIX operating system is works on two memory management schemes, These are as
follows-
1. swapping
2. demand paging.
Non-Contiguous Memory Allocation
Techniques are -
1. Paging
It is a storage mechanism that allows OS to fetch processes from the non-volatile
memory into the volatile memory in the form of pages. The partitions of non-
volatile are called as pages & volatile memory is divided into small fixed-size
blocks of physical memory, which is called frames.
Example :-
Consider a process is divided into 4 pages A0, A1, A2 and A3.
Depending upon the availability, these pages may be stored in the main memory
frames as shown in the below diagram-
A2
A3
A0
A1
Main Memory
2. Segmentation
A process is divided into division called Segments. These segments are not of
same size. There are types of segmentation:
1. Virtual memory segmentation –
Every process is divided into multiple number of segments, which do not
reside at any one point in time.
2. Simple segmentation –
Every process is divided into a number of segments, all the processes are
loaded in run time.
Segment Table
A table which stores the information about every segment of the process. It has
two columns. Column 1 gives information about size or length of the segment.
Column 2 gives information about the base address
Consider the below diagram for segment table.
Limit Base
1500 1500
1000 4700
500 4500
Segment Table
According to the above table, the segments are stored in the main memory as-
Segment- 0
Segment-3
Segment-2
Main Memory
Paging Segmentation
Paging divides program into fixed size Segmentation divides program into
pages. variable size segments.
Demand Paging
Deciding which pages need to be kept in the main memory and which need to be kept in
the secondary memory, is going to be difficult because we can’t say in advance that a
process might require a particular page at a particular moment of time. so, to beat this
problem, there comes a concept called Demand Paging. It advises keeping all pages of
the frames in the secondary memory till they are required. We can also say that, it says
that do not load other pages in the main memory till they are required.Whenever any
page is referred for the 1st time in the main memory, then that page will appear in the
secondary memory.
Page fault -
If the mention page is not available in the main memory then there will be a gap and this
theory is called Page miss or page fault.Then the CPU has to work on the missed
page from the secondary memory. If the number of page faults is very high then the
time to access a page of the system will become very high.
Thrashing -
If number of page faults is equal to the number of mention pages or the number of
page faults are so very high so that the CPU cannot remain vacant in just reading the
pages from the secondary memory then the important access time will be the time
taken by the CPU to read 1 word from the secondary memory and it will be very much
high. The process is called thrashing.
So, assume If the page fault rate is pp %, the time taken in getting a page from the
secondary memory & again restarting is S(processing time) and the memory access
time is m then the effective access time can be given as;
1. EAT = PF x S + (1 - pp) x (m)
Page Replacement
The page replacement algorithm tells us that which memory page is to be changed.
This moment of replacement is sometimes called a swap out or write to disk. Page
replacement is to be done when the requested page is not been able to access or found
in the main memory (page fault).
There are 2 main types of virtual memory, Frame allocation and Page Replacement.
Frame allocation is all about how many frames can be allocated to a process while the
page replacement tells us about determining the number of the pages which requires to
be replaced in command to make space for the requested page.
1. Due to the absence of frames, many of the pages will be occupying the main memory
and however more page faults might occur.So, if the OS specifies more frames to the
process then there can be interior fragmentation.
2. If the page replacement algorithm is not optimal then there might also lead to the
problem of thrashing. If the number of pages that are to be replaced by the requested
pages will be referred to in the near future then there will be more number of swap-out &
swap-in and so after the OS has to work on more replacements then usual which
causes performance shortage.So, the task of an optimal page replacement algorithm is
to check the page which can restrict the thrashing.
There are various types of page replacement algorithms. Each of the algorithms has a
different way of working by which the pages can be replaced.
3. FIFO →In this type algorithm, a line is to be maintained. This page which is
assigned the frame 1st will be replaced 1st. In other words, the page which stays
at the rare end of the line will be changed on the every page fault.
Linux operating system considers and works with the below devices, by the same
way we open and close a file.
Block devices(Hard-disks, Compact Disks, Floppy, Flash Memory)
Serial devices (Mouse, keyboard)
Network Devices
I/O redirection allows you to alter input source of a command as well as its output
and error messages are sent. And this is possible by the ‘<’ and ‘>’ redirection
operators.
The main advantages with block devices are the fact that they can be read
randomly. Also, serial devices are operated.
Another advantage of using block devices is that, if allows access to random
location's on the device. Also data from the device is read with a fixed block size.Input &
output to the block devices works on the "elevator algorithm"It says that it works on the
same principle, as an elevator would.
Mechanical devices like hard-disks are very slow in nature, when it comes to
data input and output compared to system memory (RAM) & Processor.
Sometimes applications have to wait for the input and output requests to
complete, because different applications are in queue for its input output operations to
complete.
The slowest part of any Linux system (or any other operating system), is the disk I/O
systems. There is a large difference between, the speed and the duration taken to
complete an input/output request of CPU, RAM and Hard-disk. Sometimes if one of the
processes running on your system does a lot of read/write operations on the disk, there
will be an intense lag or slow response from other processes since they are all waiting
for their respective I/O operations to get completed.
Output Redirection
The output from the command normally intended for normal output are often easily
diverted to a file instead.,this capability is understood as output redirection.
If the notation > file is appended to any command that normally writes its output to plain
output, the output of that command are going to be written to file rather than your
terminal.
Notice that no output appears at the terminal. this is often because the output has been
redirected from the default standard output device (the terminal) into the required file.
If a command has its output redirected to a file and therefore the file already contains
some data, that data are going to be lost. Example –
The >> operator are often used to append the output in an existing file as follows –
Input Redirection
The commands that normally take their input from the standard input can have their
input redirected from a file in this manner. For example, to count the number of lines in
the file users generated above, you can execute the command as follows −
Upon execution, you will receive the following output. You can count the number of lines
in the file by redirecting the standard input of the wc command from the file users –
Note that there is a difference in the output produced by the two forms of the wc
command. In the first case, the name of the file users is listed with the line count; in the
second case, it is not.
In the first case, wc knows that it is reading its input from the file users. In the second
case, it only knows that it is reading its input from standard input so it does not display
file name.
Redirection Commands
Following is a complete list of commands which you can use for redirection −
Sr. Command & Description
No.
4 n > file
5 n >> file
6 n >& m
7 n <& m
8 << tag
Standard input comes from here through next tag at the start of line
9 I
Note that the file descriptor 0 is normally standard input (STDIN), 1 is standard output
(STDOUT), and 2 is standard error output (STDERR).
13.6 LINUX FILE SYSTEM
Linux File System or any file system generally is a layer which is under the operating
system that handles the positioning of your data on the storage. The starting and ending
of file is not known by the system. Ever if you find any unsupported file system type.
/bin: Where core commands of Linux exists for example ls, mv.
/home: Here personal folders are allotted to the users to store his folders with his/her
name like/home/like geeks.
/lib: Here the libraries are located of the installed package. You may find duplicates in
different folders since libraries are shared among all packages unlike windows.
/media: Here is the external devices like DVDs and USB sticks that are mounted and
you can access their files here.
/sbin: Similar to /bin but difference is that the binaries here are for root user only.
/usr: Where the utilities and files shared between users od linux.
Ext2: It is the first Linux file system which allows 2 terabytes of data allowed.
Ext3: It is arrived from Ext2 which is more upgraded and has backward compatibility.
Ext4: It is quite faster which allows larger files to operate with significant speed.
JFS: old file system made by IBM. Working of this is very well with small and big files
but when used for longer time the files get corrupted.
XFS: It is old file system which works slowly with small files.
Btrfs: made by oracle. It is not stable as Ext in some distros, but you can say that it is
replacement for it if you too. It has a good performance.
The Linux file system unifies all physical hard drives and partitions into a single directory
structure. It starts at the top-the root directory.
1. pwd – This command displays the present working directory where you are
currently in.
12. cp file1 file2 – This command copies contents of file file1 into file file2
14. cat>filename – This command is used to create a file and open it in write mode
Linux Commands
Linux is an open-source free OS. It supports all administrative tasks through the
terminal. This also includes file manipulation, package installation and user
management.
File Commands
Process Management
Privilege inheritance: Normally a process executes with same privileges as the user
who launched it .Some applications require process to execute with other user
privileges
Example: passwd – setuid and setgid allow process to run with the privileges of the file
owner – Improper use of setuid and setgid can lead to security breaches – LSM
Capabilities allow administrator to assign privileges to applications as opposed to users
to prevent this situation.
13.8 Summary
13.10 Bibliography
https://www.tutorialspoint.com
https://www.geeksforgeeks.org
https://www.javatpoint.com
https://guru99.com
www.slideshare.net
13.11 Questions
1. Explain Architecture of Linux.
2. Explain memory management in Linux
3. Write short note on Process management in Linux
4. Write short note on security in Linux
UNIT 5
CHAPTER 14
Android Case study
Objectives
14.1 Android History
14.2 Android Overview
14.2.1 Features
14.2.2 Android Architecture
14.3 Android Programming
14.4 Process
14.4.1 Introduction
14.4.2 Process in the application
14.4.3 Structure of process
14.4.4 States of process
14.4.5 Process lifecycle
14.4.6 Interprocess communication
14.5 Android memory management
14.5.1 Introduction
14.5.2 Garbage collection
14.5.3 How to improve memory usage
14.5.4 How to avoid memory leaks
14.5.5 Allocate and reclaim app memory
14.6 File system
14.6.1 Flash memory- android OS file system
14.6.2 Media-based android file system
14.6.3 Pseudo file systems
14.6.4 Android / android application file structure
14.6.5 Files in android studio and explained below
14.7 Security in android
14.7.1 Authentication
14.7.2 Biometrics
14.7.3 Encryption
14.7.4 Keystore
14.7.5 Trusty trusted execution environment (TEE)
14.7.6 Verified boot
14.8 Summary
14.9 List of references
14.10 Bibliography
14.10 Questions
Versions Description
9) Android 4.1-4.3 Jelly Google released versions 4.2 and 4.3, both
Bean under the Jelly Bean label, in Oct. 2012 and
July 2013.Features include software updates,
notifications that showed more content or
action buttons, along with full support for the
Android version of Google's Chrome web
browser. Google now made Search, and
"Project Butter to speed up and improve
touch responsiveness.
10) Android 4.4 KitKat Officially launched in Sept. 2013, codename
is ―Key Lime Pie‖. It helped to expand the
overall market &was optimized to run on the
smartphones that had as little as 512 MB of
RAM. This allowed many makers to get the
latest version & installed it on a much
cheaper handset.
11) Android 5.0 Lollipop Released in the first month of 2014.This
included the support for dual-SIM Card
Feature, HD Voice calls, Device Protection to
keep thieves locked out of your phone even
after a factory reset.
12)Android 6.0 Initially called as Macadamia Nut Cookie, but
Marshmallow later was released as Marshmallow in May
2015. Features are app drawer & the first
version that had native support for unlocking
the smartphone with biometrics, Type C
support & Android pay was also there.
Google’s Nexus 6P and Nexus 5X were the
first handsets.
13) Android 7.0 Nougat Released in August 2016. Multitasking
features that designed for smartphones with
bigger screens. It included a split-screen
feature and fast switching between
applications. Other changes are made by
Google such as switching to a new JIT
compiler that could speed. Pixel, and Pixel
XL, and LG V20 were released with this
version.
14) Android 8.0 Oreo Second time Google used a trademarked
(August 21, 2017) name for it’s Android version, the first was
KitKat. Android 8.0 Oreo launched in August
2017. It included, visual changes such as
native support for picture-in-picture mode
feature, new autofill APIs;help in better
managing the passwords and fill data,
notification channels.
15)Android 9.0 Pie Released in August 2018. New features &
(August 6, 2018) updates such as battery life. Home-button
was added in this version. When swiped up it
brings the apps that were used recently, a
search bar, and suggestions of five apps at
the bottom of the screen. New option added
of swiping left to see the currently running
applications.
Android is an operating system based on the Linux kernel and other open-source
software such as smartphones and tablets.
14.2.1 Features :
Android is an operating system as well as supports great features. Few of them are
listed below: -
All these layers are responsible for different roles and features that have been
discussed below.
Linux Kernel:
This layer provides a level of abstraction between hardware and it contains all
the essential hardware drivers like camera, keypad, display. This layer is the
foundation of the android platform.
Hardware Abstraction Layer:
It provides an abstraction between hardware and the rest of the software
stack.
Libraries:
Libraries are present above the Linux kernel including open-source web
browser engine WebKit it is the well-known library, SQLite database which is
useful for storage and sharing of application data, libraries to play, and record
audio and video, SSL libraries are responsible for Internet security, etc.
Android Runtime:
This layer provides a key component called Dalvik Virtual Machine which is a
kind of Java Virtual Machine.JVM is specially designed and optimized for
Android and designed to run apps in a constrained environment that has
limited muscle power in terms of battery, processing, and memory. It contains
a set of libraries that enables developers to write code for android apps using
java programming.
Application Framework:
It provides a higher level of services to applications in the form of java
classes. Developers are allowed to make the use of these services in their
applications.
Android framework includes key services ofter are as follows –
1) Activity Manager: It controls all aspects of the application lifecycle and
activity stack.
2) Content Providers: Allows applications to publish and share their data
with other applications.
3) Resource Manager: Provides access to non-code embedded resources
such as strings, color settings, and also user interface layouts.
4) Notifications Manager: Allows applications to display notifications to the
user.
5) View System: Extensible set of views used to create application user
interfaces.
Applications:
At the top, the layer you will find all android applications. This layer uses all
the layers below it for the proper functioning of the mobile app, such
applications are Contacts Books, Calendar, Browser, Games, and many
more.
So Android holds layered or we can say a group of functionalities as software
stack that makes Android work very fluently in any device.
The best way to develop an Android app is to download Android Studio. There is a
piece of software called an Integrated Development Environment(IDE). It is offered
as a package with the Android SDK, which is nothing but a set of tools used to
facilitate Android development. It will give you everything you need in one place to
get up and get going.
Features such as the visual designer make the process easier. Powerful features are
being added to give developers access to things like cloud storage.
While Java is the official language for Android but there are so many other
languages that can be used for Android App Development.
Below mentioned are these programming languages which are currently used for
Android development:
1. Java
Java is the official. language for Android App Development and it is the
most used language as well. Apps in the Play Store are most of built
with Java and it is also the most supported language by Google. Java
has a great online community for support in case of any problems.
Java was developed by Sun Microsystems in 1995, and it is used for a
wide range of programming .applications. Java code is run by a virtual
machine. that runs on Android devices and interprets the code.
However, Java is complicated. language for a beginner to use as it
contains complex topics like constructors, null pointer, exceptions,
concurrency, checked exceptions, etc. Android Software Development
Kit(SDK) increases the complexity at a greater extent.
Development using java also requires a basic understanding of
concepts like Gradle, Android Manifest, and the markup language
XML.
2. KOTLIN
Kotlin is a cross-platform programming language that is used as an
alternative to Java for Android App Development. It has been
introduced as a secondary ―official‖ Java language in 2017.
It can inter-operate with Java and it runs on the Java Virtual Machine.
3. C++
C++ is used for Android App Development using the Android Native
Development Kit(NDK). An app cannot be created using C++ and the
Native Development Kit is used to implement parts of the app in C++
native code. This helps in using C++ code libraries for the app as
required.
While C++ is useful for Android App Development in some cases, it is
much more difficult to set up and is much less flexible. For applications
like 3D games, this will use out some extra performance from an
Android device, which means that you’ll be able to use libraries written
in C or C++.
It may also lead to more bugs because of the increased complexity.
So, it is better to use Java as compared to C++ as it does not provide
enough gain to offset the efforts required.
4. C#
C# is a little bit similar to Java and so it is ideal for Android App
Development. Like Java, C# also implements garbage collection so
there are fewer chances of memory leaks. And C# also has a cleaner
and simpler syntax than Java which makes coding with it comparatively
easier.
Earlier, the biggest drawback of C# was that it could run only on
Windows systems as it used the .NET Framework. However, this
problem was handled by Xamarin.
Android is a cross-platform implementation of the Common Language
Infrastructure. Now, Xamarin. The android tool can be used to write
native Android apps and share the code across multiple platforms.
5. Python
It is used for Android App Development even though Android doesn’t
support native Python development. This is done using various tools
that convert the Python apps into Android Packages that can be run on
Android devices.
An example of this can be Kivy that is an open-source Python library
used for developing mobile apps. It supports Android and also provides
rapid app development. However, a downside to this is that there won't
be native benefits for Kivy as it isn’t natively supported.
6. Corona
It is a software development kit that is used for developing Android
apps using Lua. It contains two operational modes, i.e. Corona
Simulator and Corona Native. The Corona Simulator is used to build
apps directly whereas the Corona Native is used to integrate the Lua
code with an Android Studio project to build an app using native
features.
While Lua is a little limited as compared to Java, it is also much simpler
and easy to learn. It is mostly used to create graphics applications and
games but is by no means limited to that.
We need to use a text editor like Notepad++ to enter your code and
you can run said code on an emulator without even needing to compile
first. When we are ready to create an APK and deploy, we will be able
to do this using an online tool.
7. Unity
Unity is a "game engine," which means it provides things like physics
calculations and 3D graphics rendering and an IDE like Android Studio.
It is an open-source tool, which makes it incredibly easy to create our
games, and the community is strong, which means we get a lot of
support. With just a few lines of code, we have a basic platform game
set up in less than an hour. It's multiplatform and is used by many
game studios.
It is a great way to learn object-oriented programming concept as the
objects are an object.
This is used to become a game developer.
8. PhoneGap
The last simple option you can choose to develop Android apps
is PhoneGap unless we want to turn instead to an app builder
program.
PhoneGap is powered by Apache Cordova and it allows you to create
apps using the same code you would normally use to create a website:
HTML, CSS, and JavaScript. This is then shown through a ―WebView‖
but packaged like an app. It acts like a mediator, which allows
developers to access the basic features of the phone, such as the
camera.
This is not real Android development, though, and the only real
programming will be JavaScript.
Conclusion
There are a lot of apps such as Chat messengers, Music players, Games.
Calculators. etc. that can be created using the above languages.
No language is correct for Android Development.
So, it's upon you to make the correct choice of language based on your
objectives and preferences for each project.
Databases that can be used with Android
1. SQLite
2. Firebase
With Firebase, we can focus our time and attention on developing the best
possible applications for our business. The operation and internal functions
are very solid. They have taken care of the Firebase Interface. We can spend
more time in developing high-quality apps that users want to use.
3. Realm DB
4. ORMLite
14.4 Process
14.4.1 Introduction
A process is a ―program in execution‖.It is generally used to accomplish a task, a
process needs resources. For instance, CPU file, memory, etc. Resources are
allocated to processes in two stages
● The stage when the process was created
● Dynamically allocate the process while they are running
A process is more than coding or program of code; it also includes current activity,
the content of processor's registers, etc. A program can also be called a passive
entity and a process can also be called an active entity. It also contains a feature
which is known as a program counter which is responsible for specifying the next
instruction to be executed. Eg. Word processor can be thought of as a process. So
when we talk about a passive entity it would be like a file containing a set of
instructions saved on a disk which is also known as an executable file, whereas a
process is meant to be an active entity which is backed by a program counter which
in turn specifies the next instruction to be executed along with a set of associated
resources. In other words, the program converts into a process when it is loaded into
memory.
2. Generally, only a few foreground processes exist at any given time. They are
killed only as a last resort—if memory is so low that they cannot all continue to
run. Generally, at that point, the device has reached a memory paging state,
so killing some foreground processes is required to keep the user interface
responsive.
3. Visible process
A process that does not have any foreground components, but still can affect
what the user sees on the screen. A process is considered to be visible if all
the following conditions are true: It hosts an Activity that is not in the
foreground, but it is still visible to its user (its onPause() method called). This
could occur, for eg if the foreground activity starts a dialog, which would allow
the previous activity to be seen behind it. It hosts the Service that is bound to
be visible (or foreground) activity. A visible process is considered extremely
important and will not be killed unless doing so is required to keep all
foreground processes running.
4. Service process
A process that is running on the service that has been started with the
startService() method and does not fall into either of the two higher
categories. Although service processes are not directly tied to anything the
user sees, they are generally doing what the user cares about ( like playing
music in the background or downloading data on the network), and so the
system keeps them running unless there's not enough memory to remember
them along with all foreground and visible processes in them.
5. Background process
A process that is holding an activity which is not currently visible to the user
(the activity's onStop() called). These processes have no direct impact on
their user experience, and the system can kill them at any time to reclaim
memory for a foreground, visible, or service process. Usually, many
background processes are running, so they are kept in the least recently used
list to ensure its process with the activity that was most recently seen by the
user is last to be killed. If the activity implements the lifecycle methods
correctly, and saves its current state, killing its process will have no visible
effect on its user experience because when its user navigates back to its
activity, the activity restores all of its visible states.
6. Empty process
A process that does not hold any active application components is the only
reason to keep the process alive is for its caching purposes, to improve
startup time for its next time a component needs to run it. The system
sometimes kills these processes to balance the system resources between
its process caches and the underlying kernel caches
Android ranks process at the highest level it can, based on the importance of
their components which are currently active in the process. For eg. if the process
hosts a service and a visible activity, the process is ranked as a visible process, not
a service process.
In addition to it, any process's ranking might increase because other processes are
dependent on it so a process that is serving another process can be never ranked
lower than another process it is serving. For example, if the content provider in
process A is serving a client in process B, or if the service in process A is bound to a
component in process B, process A is considered at least important as process B.
Because when a process is running the service is ranked higher than the process
with its background activities, an activity that is long-running operation might do well
to start the service for that operation, rather than simply creating the worker thread—
particularly if the operation is likely to outlast the activity. For eg. an activity that's
uploading the picture to a web site will be starting a service to perform the upload so
the upload will continue in the background even if the user leaves the activity. Using
the service guarantees that all the operations will be having at least "service
process" priority, regardless of what happens to the activity. This is the same reason
why the broadcast receivers should always employ services rather than simply put
time-consuming operations in a thread.
There are two major techniques related to the inter process communication and they
are namely;
Intents: These enable the application to select an Activity based on the action you
want to invoke and the data on which they operate. Path to an application is needed
to use its functions and exchange data with it. With intent objects, data can be used
to pass objects in both directions. It enables high-level communication.
Remote methods: By this we mean the remote procedure calls with these APIs can
be accessed remotely. With this calls the methods to appear to be local which are
executed in another process.
14.5.1 INTRODUCTION
In Android memory management instead of providing swap space, it uses paging
and a map which means at your application touches cannot be paid until you release
all your preferences now in Android the Dalvik virtual Machine heap size for the
application process limited and the size of 2MB and the maximum allocation is
limited to 36 MB examples of large applications are photo editor, camera, gallery,
and home screen.
The background application processes in Android are stored in the LRU cache.
according to the cat strategy, it will kill processes in the system when it runs slow
and it will also consider the application which is the largest consumer.
If kind wants to make make an app run and live longer in the background only to
deallocate unnecessary memory in the four more into the background system will
generate an error message or terminate the application.
Android memory heap is purely based on the life and size of an object been
allocated.
The duration of garbage collection depends upon the generation of objects and
collecting and how many active objects are there in each of the generations.
The memory heap of android may be a generalized one, meaning that there are
different allocations that it tracks, supported the expected life and size of an object
being allocated. For example, recently allocated objects belong within the Young
Generation.
Each heap generation has its dedicated upper limit on the quantity of memory that
objects there can occupy. Any time a generation starts to refill, the system executes
a garbage pickup event to release memory.
Even though garbage pickup is often quite fast, it can still affect your app's
performance. You don't generally control when a garbage pickup event occurs from
within your code.
When the standards are satisfied, the system stops executing the method and
begins garbage pickup. If garbage pickup occurs within the middle of an intensive
processing loop like animation or during music playback, it can increase the time
interval.
1. One should take care of the design pattern with fractions it can help to build a
more flexible software architect. In the mobile world, abstraction may involve
side effects for its extra code to be executed, which will cost more time and
memory. Unless abstraction can provide application is a significant benefit.
2. Avoid using "enum". Do not use the enum because it doubles the memory
allocation than ordinary static constant.
3. Instead of HashMap try to use the optimized sparse array, sparse boolean
array, and long sparse array containers. Hashmap allocates and entry object
during every mapping which is a memory inefficient action, also the low-
performance behavior, "autoboxing/unboxing" is spread all over the usage.
Instead, sparse array-like containers map keys into the plane array.
4. To avoid this kind of leakage do not keep long references to contacts activity
and id3 using the context-application instead of context-activity.
5. Threads in java are the root of garbage collection that is a DVM keeps data
friends to all activity threads in the runtime system and threads are left
running will never be eligible for garbage collection.
After the garbage collection process, Dalvik walks the heap and finds the unused
pages, then returns these pages to the kernel using the advice.
This informative piece is for people who are thinking to develop ROMs, Apps,
and a lot of other things on the Android operating system. Without wasting a minute
more let us begin with a detailed look at the Android file system. We would not just
be naming the file systems in android we would also give you a brief explanation
about a particular file system in detail understanding.
1. exFAT: Created by Microsoft for flash memory, the exFAT file system is not a part
of the standard Linux kernel. However, it still provides support for Android devices in
some cases. It stands for Extended File Allocation Table Application.
2.F2FS: Users of Samsung smartphones are bound to have come across this type of
file system Application if they have been using the smartphone for a while. F2FS
stands for Flash-Friendly File System Application, which is an Open Source Linux file
system. This was introduced by Samsung 4 years ago in the year 2012.
3. JFFs2: It stands for the Journal Flash File System version 2. This is the default
flash file system for the Android Application Open Source Project kernels. This
version of the Android File System has been around since the Android Ice Cream
Sandwich Operating system was released.
1. EXT2/3/4: Ext, which stands for the extended file systems, are the standards for
the Linux file system. The latest out of these is the EXT4, which has now been
replacing the YAFFS2 and the JFFS2 file systems on Android smartphones.
3. vFAT: An extension to the aforementioned FAT 12, FAT 16, and FAT 32 file
systems, the vFAT is a kernel module seen alongside the msDOS module. External
SD cards that help expand the storage space are formatted using VFAT.
2. Rootfs: Rootfs acts as the mount point, and it is a minimal file system. It is located
at the mount point ―/‖.
3. Process: The process file system has files that showcase the live kernel data.
Sometimes this file system Application development also reflects several kernel data
structures. These numbers directories are reflective of process IDs for all the
currently running tasks now.
4. Systems: Usually mounted on the /sys directory. The sysfs file system app helps
the kernel identify the devices. Upon identifying a new device, the kernel builds an
object.
5. Tmpfs: A temporary file system, tmpfs is usually mounted on /dev directory. Data
on this is lost when the device is rebooted.
3. Drawable: A Drawable folder contains a resource type file (something that can
be drawn). Drawables may take a variety of files like Bitmap Nine Patch, Vector
(XML), Shape, Layers, States, Levels, and Scale.
4. Layout: A layout defines the visual structure for the user interface, such as the
UI for an Android application. This Layout folder stores Layout files that are
written in XML language we can add additional layout objects or widgets as
child elements to gradually build a view hierarchy that defines your layout file.
5. Mipmap: Mipmap Android folder contains the Image Asset file that can be used
in Android Studio Application. Generate the following icon types like Launcher
icons, Action bar, and tab icons and Notification icons there.
8. Styles.xml: Here styles.xml file contains resources of the theme style in the
Android application. It is written in XML language for all activities in general in
android.
File System provides an interface to a file system and is the factory for objects to
access files and other objects in the file system. The default file system Application,
obtained by invoking the method, provides defines methods to create file systems
that provide access to other types of file systems.
File systems vary in some cases, the file system of android Application is a
single hierarchy of files with one top-level root directory. In other cases, it may have
several distinct file hierarchies, each with its top-level root directory Application. The
getRootDirectories method may be used to iterate over the root directories in the
system. A file system is typically composed of one or more underlying File Store that
provides the storage for the files. File stores can also vary in the features they
support, and the file attributes and meta-data that they associate with files in this
Applications.
A file system is open upon creation and can be closed by invoking a close
method. Once closed any further attempt to access objects in the file system causes
ClosedFileSystemException to be thrown. File systems created by the
default FileSystemProvider cannot be closed in the Android application.
A FileSystem can provide read-only or read and write access to the file
system. Whether or not a file system provides read-only access is established when
the FileSystem is created and can be tested by invoking it is a read-only method.
Attempts to write to file stores utilizing an object associated with a read-only file
system throws ReadOnlyFileSystemException.
14.7.2 Biometrics
Android 9 and up consists of a BiometricPrompt API that allows the developers to
integrate biometric authentication within their applications. Only strong biometrics
can integrate with BiometricPrompt.
14.7.3 Encryption
After the device is encrypted, all the data created by the user is automatically
encrypted before committing it to the disk and also all the reads automatically
decrypts the data before sending it back to their respective calling process.
Encryption gives assurances that if an unauthorized user tried to access the data,
they would not be able to read the content of the data.
14.7.4 Keystore
The Keystore system allows you to store all cryptographic keys into a container to
make it more difficult for the hacker to extract it from the device. Once keys are
stored in the KeyStore, they can be used for various cryptographic procedures with
the key remaining non-exportable. It offers features such as to restrict how and when
the keys can be used, such as demanding authentication of users for key use and
restricting usage of keys only in some cryptographic methods.
14.8 Summary
Android made this version authorized in the year 2008, with Android 1.0.
Finally, Google opted to drop the tradition of naming the Android version after
sweets, desserts, and candies. It was launched in September 2019.
Android OS provides a beautiful and intuitive user interface.
Android is a stack of components of the software which is divided into five
layers.
Android ranks process at the highest level it can, based on the importance of
their components which are currently active in the process. For eg. if the
process hosts a service and a visible activity, the process is ranked as a
visible process, not a service process.
The Dalvik virtual machine maintains track of memory allocation. Once it gets
to know that memory is no longer used by any program if freeze into a heap
without any participation from the programmer.
14.10 Bibliography
https://www.tutorialspoint.com/
https://www.geeksforgeeks.org/
https://www.javatpoint.com/java-tutorial
https://guru99.com
14.11 Questions
CHAPTER 15
Objectives
15.1 History of Windows
15.2 Programming Windows
15.3 System Structure
15.10 Summary
15.12 Bibliography
15.13 Questions
15.1 History of Windows
Windows 10 is a Microsoft
operating system for personal
computers, tablets, encircled
devices and internet of things
devices. Microsoft free Windows
10 in July 2015 as a follow-up
to Windows 8. The company has
said it will update Windows 10 in
eternity rather than release a
new, complete operating system
as a beneficiary.
Resource Files: Data files that are compiled into one or the other an
executable or library WPF assembly.
Content Files: Standalone data files that have an open association with an
executable WPF assembly.
Site of Origin Files: Standalone data files that have no suggestion with an
executable WPF assembly.
6. Compiling Windows Program: -
Click the Run button (displayed below with the arrow) and pause a few seconds.
This compiles the program to an EXE file and runs it: When the program runs,
you will detect the dialog on the screen. It appears like this:
Above figure shows a flow diagram for the formation of a Windows programs. In
this figure the source code file gets converts to objective file from the compilers
same as in the DOS. In windows programs the linker gets a few extra info from a
small file called the "module definition file" with the file name extension ".DEF".
This file tells the linker how to collect the program. The linker combines the
module definition file info and the object file to make an incomplete .EXE file. The
incomplete .EXE file absences the resource data. The main variance between
Windows programs and DOS programs is in the compilation of the resource data
file with the extension of ".RES". In DOS programs there is no resource data but
in windows program the resource data is added to the incomplete.EXE file to
create the complete executable program. The resource data is essentially stuck
onto the end of the program's code and develops part of the programs file. In
addition to adding the resource data the resource compiler writes the Windows
version number into the program file.
DIAGRAM: -
Many operating systems have modest structure.
MS-DOS- written to deliver the most functionality in the smallest
space
Not distributed into modules
Although MS-DOS has some structure, its interfaces and levels of
functionality are not well detached
15.3.2 Layered Structure
The operating system is divided into a numeral of layers (levels), each constructed
on top of lower layers. The lowest layer (layer 0), is the hardware; the highest (layer
N) is the user interface.
A thread is the object within a process that can be planned for execution. All threads
of a process part its virtual address space and system resources. In adding, each
thread supports exception handlers, a scheduling importance, thread local storage, a
unique thread identifier, and a set of creations the system will use to save the thread
setting until it is scheduled.
• Upgrading performance
• Execution of multiple processes
• Utilization of memory space
• Correct relocation of information
• Protection of data from illegal change
• Provision to share the data
• Utilization of small free space
Paged memory management: Memory is divided into fixed sized units called page
frames, used in a virtual memory environment.
Each 64-bit process has its own space while each 32-bit application runs in a
virtual 2 GB Windows-On-Windows (WOW).
Cache is a sort of memory that is used to increase the rapidity of information access.
Normally, the data required for any process resides in the main memory. Though, it
is moved to the cache memory temporarily if it is used commonly enough. The
process of storing and retrieving information from a cache is known as caching.
A computer comprises of several devices that offer input and output (I/O) to and
from the outside world. The Windows kernel-mode I/O manager manages the
communication among applications and the interfaces providing by device drivers.
15.6.1 File Buffering: -
This covers the various considerations for application control of file buffering, also
known as unbuffered file input/output (I/O). File buffering is usually handled by the
system behind the scenes and is considered part of file caching within the Windows
operating system. Although the terms caching and buffering are sometimes used
interchangeably, this topic uses the term buffering specifically in the context of
explaining how to interact with data that is not being cached (buffered) by the
system, where it is then mostly out of the direct control of user-mode applications.
When opening or creating a file through the CreateFile function, the
FILE_FLAG_NO_BUFFERING flag can be specified to disable system caching of
information being read from or written to the file. While this gives whole and direct
control over data I/O buffering, in the instance of files and similar devices there are
data alignment requirements that must be considered.
NTFS (NT file system, sometimes New Technology File System) is the file
system that the Windows NT operating system uses for storing and recovering
files on a hard disk. NTFS is the Windows NT corresponding of the Windows 95
file allocation table (FAT) and the OS/2 High Performance File System (HPFS).
However, NTFS offers a number of enhancements over FAT and HPFS in terms
of performance, extendibility, and security.
Notable features of NTFS include:
• Use of a b-tree directory structure to keep path of file clusters
• Info about a file's clusters and extra information is kept with each cluster,
not just a governing table
• Support for very large files (up to 2 to the 64th power or around 16 billion bytes
in extent)
• An access control list (ACL) that lets a server administrator control who can
access detailed files
• Integrated file compression
• Support for names created on Unicode
• Support for long file names in addition to "8 by 3" names
• Data security on equally removable and fixed disks
Diagram
One of the basic beliefs of Windows Security is that each process runs on
behalf of a user. So, each process running is connected with a security context.
security context is a bit of cached data about a user, counting her SID, group SIDs,
privileges. A security principal is an entity that can be positively recognized and
confirmed via a technique known as authentication. Security principals in Windows
are allocated on a process-by-process basis, via a little kernel object called a token.
Each user, computer or group account is a security principal on the system running
Windows Server 2003, Windows 2000, and Windows XP. Security principal obtain
permissions to access resources such as files and folders.
1) User principals
2) Machine principals
3) Service principals
Security Identifier: (SID)
Users reference their accounts by usernames but the Operating system, internally,
references accounts by their security identifier. SID’s are unique in their scope
(domain or local) and are never reused. So, they ae used to uniquely identify user
and group account in Windows. By default, the operating system SID comprises of
various parts S <revision> <identifier authority> <subauthorities> <relative
identifiers>
Access Token: - A token is a kernel object that caches part of a user's security
profile, containing the user SID, group SIDs, and privileges. A token contains of
the following components. accountID, groupID, Rights, Owner, Primary group,
Source, Type, Impersonation level, statistics, Restricted SID’s, SessionID
Account Security: - User accounts are core unit of Network security. In Win
Server 2003 & Win2000, domain accounts are kept in Active Directory directories
databases, where as in local accounts, they are kept in Security Accounts
Manager database. The passwords for the accounts are stored and maintained
by System Key. Though the accounts are protected by default, we can secure
them even further. Go to Administrative tools in control panel (only when you are
logged in as an admin) and click on ―Local Security and Settings.‖
Account Lock out policies: - Account lockout period: Locks out the account
after a specific period (1- 99,999 minutes). This feature is only exists is Win Ser
2003, Win 2000, but not in Windows XP.
15.10 Summary
In this Chapter, we learn History of windows, Process and thread, System structure,
Memory Management in Windows, Windows IO Management, Windows NT file
System, Windows Power Management and Security in Windows.
15.12 Bibliography
https://www.tutorialspoint.com/
https://www.geeksforgeeks.org/
https://www.javatpoint.com/java-tutorial
https://guru99.com
https://docs.microsoft.com/
https://www.installsetupconfig.com/
15.13 Questions