Operating System 2018

Unit – I Operating System 1. Introduction A computer system has many resources (hardware and software), which may be require to complete a task. The commonly required resources are input/output devices, memory, file storage space, CPU etc. The operating system acts as a manager of the above resources and allocates them to specific programs and users, whenever necessary to perform a particular task. Therefore operating system is the resource manager i.e. it can manage the resource of a computer system internally. The resources are processor, memory, files, and I/O devices. In simple terms, an operating system is the interface between the user and the machine.

An operating system (OS), in its most general sense, is software that allows a user to run other applications on a computing device. While it is possible for a software application to interface directly with hardware, the vast majority of applications are written for an OS, which allows them to take advantage of common libraries and not worry about specific hardware details. The operating system manages a computer's hardware resources, including:  Input devices such as a keyboard and mouse  Output devices such as display monitors, printers and scanners  Network devices such as modems, routers and network connections  Storage devices such as internal and external drives The OS also provides services to facilitate the efficient execution and management of, and memory allocations for, any additional installed software application programs.

Some operating systems were developed in the 1950s, when computers could only execute one program at a time. Later in the decade, computers included many software programs, sometimes called libraries, which were linked together to create the beginning of today's operating systems.

The OS consists of many components and features. Which features are defined as part of the OS vary with each OS. However, the three most easily defined components are:  Kernel: This provides basic-level control over all of the computer hardware devices. Main roles include reading data from memory and writing data to memory, processing

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 1

Operating System 2018

execution orders, determining how data is received and sent by devices such as the monitor, keyboard and mouse, and determining how to interpret data received from networks.  User Interface: This component allows interaction with the user, which may occur through graphical icons and a desktop or through a command line.  Application Programming Interfaces: This component allows application developers to write modular code. Examples for OSs include Android, iOS, Mac OS X, Microsoft Windows and Linux.

1.1. Two Views of Operating System 1. User's View 2. System View

Operating System: User View The user view of the computer refers to the interface being used. Such systems are designed for one user to monopolize its resources, to maximize the work that the user is performing. In these cases, the operating system is designed mostly for ease of use, with some attention paid to performance, and none paid to resource utilization. Operating System: System View Operating system can be viewed as a resource allocator also. A computer system consists of many resources like - hardware and software - that must be managed efficiently. The operating system acts as the manager of the resources, decides between conflicting requests, controls execution of programs etc.

1.2. Operating System Management Tasks 1. Processor management which involves putting the tasks into order and pairing them into manageable size before they go to the CPU. 2. Memory management which coordinates data to and from RAM (random-access memory) and determines the necessity for virtual memory. 3. Device management which provides interface between connected devices. 4. Storage management which directs permanent data storage. 5. Application which allows standard communication between software and your computer. 6. User interface which allows you to communicate with your computer.

1.3. Basic functions of operating systems: 1. Memory Management It manages the allocation of memory of system for different processes. It manages both the primary memory and secondary memory. 2. Processor Management It manages all the running processes in computer system. A process is simply a program that is run by a user on computer system. 3. Security Management

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 2

Operating System 2018

It ensures the security of computer system from the various threats and viruses attacks. An operating system uses various techniques such as authentication, authorization, cryptography etc. for ensuring security of compute system. 4. Device Management This function of operating system is used to manage different devices that are connected with the computer system. An operating system interact with hardware device through specified device drivers.

5. File Management An operating system manages the files and directories of computer system. A file can be defined as a collection of information or data that is store in the memory of computer system. An operating system allow us to create, delete, save, edit files in a computer system.

1.4.Types of operating system: Many different types of operating systems are involved till date. The operating systems are improved in terms of their capabilities. The modern days operating systems allows multiple user to carry out multiple tasks simultaneously. Based on their capabilities and the types of application supported, the operating systems can be divided into following six major categories. 1. Batch processing operating systems 2. Multi user operating systems 3. Multitasking operating systems 4. Real time operating systems 5. Multi processors operating systems 6. Embedded operating systems

Batch processing operating system The batch processing operating system is capable of executing one job at a time. In batch processing operating system the jobs are combined in form of batch and then these batches are given to system as an input data. The job in batches are processed on first com first serve basis. After execution of one job operating system fetches another job from input data. There is no need of human interaction before fetching the next job after completion of any job.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 3

Operating System 2018

Multi user operating system The multi user operating system uses to use a system by multiple users. In other word multi user operating system allows a number of users to work simultaneously on a single computer system. These types of operating systems are specially designed for the multi user system.

Examples of multi user operating systems includes Unix, Linux, Windows 2000 and VM - 386.

Multitasking operating system The multitasking operating system allow a user to give multitask at a same time on a single computer system multitasking operating system are also known as multiprocessing operating system and multiprogramming operating system. The first multitasking operating system is created in 1960s. The number of tasks processed simultaneously by this operating system is depending upon speed of CPU, the capacity of memory and size of programs.

Examples of multitasking operating systems are Linux, Unix, windows 2000, windows XP, windows 10.

Real time operating system The real time operating system is similar as multitasking operating system. However, these operating systems are specially designed to handle real time applications. Real time applications are those applications which have to execute within a specific period of time. Therefore, time is major constraint for these applications. The different examples of real time applications are robots, machine learning etc.

There are mainly two types of real time operating system. Hard real time operating system and soft real time operating system.

Examples of real time operating systems are MTOS, Lynx, RTX etc.

Multiprocessor operating system The multiprocessor operating system allows the computer system to use more than one CPU in a single system for executing more than one or multiple processes at a time. A computer system having multiple CPU process faster than a system which contains a single CPU.

Examples of multiprocessor operating systems are Linux, Unix, windows 2000 etc. Embedded operating system

The embedded operating system is similar to real time operating system. This operating system is installed on an embedded computer system which is primary used to perform computational tasks in electronic devices.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 4

Operating System 2018

1.5. History of Machine Hardware Computer was referred as the machine which can carry the task of computation form the end of the 19th century. However now it is not just a calculation machine, it has diversified applications and it has even revolutionized the industry. If we make a deep analysis regarding the history of the computer we have to go back in 16th century. However the true progress in this field started in early nineteenth century.

Early Digital Computers If we briefly analyze the history of computer hardware, we can see innumerable changes in the hardware overtime. Zues was introduced in Germany in 1941; it uses binary coding for its operation. It involves the lector mechanical computing mechanism. Then after one year in 1942 Attansoff Berry computer came to surface with electric binary computing mechanism. Its origin was USA. Colluses Mark was a UK based technology and it emerged in 1944. It was also based on binary numeral principle. In the same year in Harvard, Harvard Mark IBM ASCC was introduced. ENIAC was introduced in 1946; it had its origin from UK. The modified version of ENIAC was introduced in 1948, as in 1949 EDSAC, Manchester Mark and CSIRAC came forward. The early computers and the associated hardware were really expensive and heavy. For example first portable computer weighed about 25kg.

History of Associated Hardware With the development in computers, the hardware of the Pc was also improved. The first mouse was invented by Douglas Engelbart in 1963. it was a relatively instable device which was set at a 90 degrees angle . This mouse had no ball. The optical mouse was invented in 1980; it did not receive widespread popularity during the early phase of its invention. First portable computer was introduced by IBM in 1975, it was of the size of a small suit case and it also required external power in order to operate. The use of random access memory (Ram) started in 1951. This memory was earlier known as magnetic core memory. The invention of Ram can be contributed to An Wang and Jay Forrester. Core memory was the base of early computers which was replaced in 1970 by integrated silicone RAM chips. The first hard disk was introduced by IBM, it was used in IBM 305RAMAC. It became part of the first IBM computers in 1960‘s. It has a data transfer rate of about 8,800 characters per second.

Development in Additional Hardware Today computer is far more than a calculation device. It can serve many other countless purposes like networking and web browsing, advance computing requirements etc. The other important hardware devices like printers, web cam, audio systems and web servers are also part and parcel of today‘s PC. Hence their history is also very important. Let‘s read when the first laser printer came into use. The first laser printer was conceived by Gary Starkweather in 1969. However it did not become popular unless IBM introduced their branded laser printer known as IBM 3800 in 1976. It was as large as a room. The first web server was introduced in 1991, which was used by Tim Berners while discovering World Wide Web at CERN. This web server was a next workstation which helped in putting out

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 5

Operating System 2018

first web page online. If we go through the history of the hardware, 70% contribution in this field can be contributed to the IBM. Another important invention of this company was floppy Disks. Floppy disks were invented in 1970 and they were used till 1990‘s however today there use is history. These remarkable inventions changed our lives now the world has become a global village due to the spread of networking technologies. However the foundation for these technologies came from early development in hardware.

1.6. History of Operating System Development The First Generation (1940's to early 1950's) When electronic computers where first introduced in the 1940's they were created without any operating systems. All programming was done in absolute machine language, often by wiring up plugboards to control the machine's basic functions. During this generation computers were generally used to solve simple math calculations, operating systems were not necessarily needed.

The Second Generation (1955-1965) The first operating system was introduced in the early 1950's, it was called GMOS and was created by General Motors for IBM's machine the 701. Operating systems in the 1950's were called single-stream batch processing systems because the data was submitted in groups. These new machines were called mainframes, and they were used by professional operators in large computer rooms. Since there was such as high price tag on these machines, only government agencies or large corporations were able to afford them.

The Third Generation (1965-1980) By the late 1960's operating systems designers were able to develop the system of multiprogramming in which a computer program will be able to perform multiple jobs at the same time.The introduction of multiprogramming was a major part in the development of operating systems because it allowed a CPU to be busy nearly 100 percent of the time that it was in operation. Another major development during the third generation was the phenomenal growth of minicomputers, starting with the DEC PDP-1 in 1961. The PDP-1 had only 4K of 18-bit words, but at $120,000 per machine (less than 5 percent of the price of a 7094), it sold like hotcakes. These microcomputers help create a whole new industry and the development of more PDP's. These PDP's helped lead to the creation of personal computers which are created in the fourth generation.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 6

Operating System 2018

The Fourth Generation (1980-Present Day) The fourth generation of operating systems saw the creation of personal computing. Although these computers were very similar to the minicomputers developed in the third generation, personal computers cost a very small fraction of what minicomputers cost. A personal computer was so affordable that it made it possible for a single individual could be able to own one for personal use while minicomputers where still at such a high price that only corporations could afford to have them. One of the major factors in the creation of personal computing was the birth of Microsoft and the Windows operating system. The windows Operating System was created in 1975 when Paul Allen and Bill Gates had a vision to take personal computing to the next level. They introduced the MS-DOS in 1981 although it was effective it created much difficulty for people who tried to understand its cryptic commands. Windows went on to become the largest operating system used in techonology today with releases of Windows 95, Windows 98, WIndows XP (Which is currently the most used operating system to this day), and their newest operating system Windows 7. Along with Microsoft, Apple is the other major operating system created in the 1980's. Steve Jobs, co founder of Apple, created the Apple Macintosh which was a huge success due to the fact that it was so user friendly. Windows development throughout the later years were influenced by the Macintosh and it created a strong competition between the two companies. Today all of our electronic devices run off of operating systems, from our computers and smartphones, to ATM machines and motor vehicles. And as technology advances, so do operating systems.

1.7. The Parts of an Operating System Operating systems are built out of two main parts:  The kernel;  System programs. The kernel is the heart of the operating system. It is the first program loaded when the computer starts up, it manages computer resources, and it handles requests from system programs and applications.

System programs run on top of the kernel. They aren't used to perform useful work, instead, they are the programs necessary to connect the kernel to user applications and peripheral devices. Device drivers, file systems, networking programs, and system utilities like disk defragmeters are all examples of system programs.

Application programs aren't part of the operating system and are the programs used to perform useful work. Word processing applications, browsers, and media player are common

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 7

Operating System 2018

types of application programs. Application programs are managed and enabled by the kernel, and use system programs to access computer periphery devices and hardware.

Programming Languages In order to develop an operating system, you will need to master at least two programming languages:  Low-level assembly language;  A high-level programming language. Assembly languages are used to communicate directly with a CPU. Each type of CPU speaks a machine language and there is just one corresponding assembly language for each type of CPU. The most common computer architecture is x86, it was originally developed by Intel and is now used by a wide range of computer chip manufacturers including AMD, VIA, and many others. In this guide we will point you in the direction of learning x86 assembly language.

High-level programming languages work with multiple computer architectures. C is the programming language most commonly used and recommended for writing operating systems. For this reason, we are going to recommend learning and using C for OS development. However, other languages such as C++ and Python can also be used. x86 Assembly Language The x86 Assembly Guide is a great place to start learning assembly language. This short document provides a brief overview of x86 assembly language and will set the stage for the more advanced resources you'll be moving on to next.

Programming from the Ground Up by Jonathan Bartlett is one of the defining books of the assembly language landscape. This book uses assembly language as the basis for learning computer science and programming. This resource is also available from the Internet Archive.

The Art of Assembly Language by Randy Hyde is another iconic text in the world of assembly language education. Originally written specifically for Hyde's programming courses at Cal Poly and UC Riverside, the text was released as an HTML ebook in the mid-1990s and is recognized as a defining work within the field. The text is also hosted as a series of PDF files by the Yale FLINT Group. If you want to use a traditional textbook to learn about x86 assembly language two of the most commonly used and highly recommended texts are:  Assembly Language Step-by-Step: Programming with Linux by Jeff Duntemann;  Modern X86 Assembly Language Programming by Daniel Kusswurm.

1.8. Object Oriented Design An object-oriented operating system is an operating system that uses object- oriented design principles.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 8

Operating System 2018

An object-oriented operating system is in contrast to an object-oriented user interface or programming framework, which can be run atop a non-object-oriented operating system like DOS or Unix.

There are already object-based language concepts involved in the design of a more typical operating system such as Unix. While a more traditional language like C does not support object-orientation as fluidly as more recent languages, the notion of, for example, a file, stream, or device driver (in Unix, each represented as a file descriptor) can be considered a good example of objects. They are, after all, abstract data types, with various methods in the form of system calls whose behavior varies based on the type of object and whose implementation details are hidden from the caller.

Object-orientation has been defined as objects + inheritance, and inheritance is only one approach to the more general problem of delegation that occurs in every operating system. Object-orientation has been more widely used in the user interfaces of operating systems than in their kernels.

What exactly is an an ObjectOriented OperatingSystem?  an operating system implemented using the techniques of object orientation (i.e. implemented in an ObjectOrientedProgrammingLanguage using inheritance, PolyMorphism, etc.)?  an operating system designed according to the principles of object orientation (i.e. the basic abstractions provided by the operating system are represented internally and externally as objects with state, behavior, and identity, and can be acted upon and maybe even extended as one would act and extend objects e.g. in a SmalltalkProgrammingEnvironment)?  Consider device drivers, interrupts, and file systems. Device drivers were some of the first polymorphic components. New drivers could be loaded or compiled into an operating system, without the OS having prior knowledge of the driver type. The driver only had to conform to a specific interface. Interrupts provided a very basic messaging system. Hardware or software could call an interrupt without know precisely what would handle it or even if it would be handled. Software and occasionally hardware would be installed to handle the interrupt and would need to register itself to the system to be the interrupt handler. File systems are really an extension of the device driver example, but a routine is really unconcerned where a file exists; it merely reads from it and writes to it. The details of whether the file is on a floppy disk, a hard drive, or a remote file server are hidden.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 9

Operating System 2018

Unit – II Memory Management 2. Introduction of Memory Management Memory management is the functionality of an operating system which handles or manages primary memory and moves processes back and forth between main memory and disk during execution. Memory management keeps track of each and every memory location, regardless of either it is allocated to some process or it is free. It checks how much memory is to be allocated to processes. It decides which process will get memory at what time. It tracks whenever some memory gets freed or unallocated and correspondingly it updates the status.

Memory management is the process of controlling and coordinating , assigning portions called blocks to various running programs to optimize overall system performance. Memory management resides in hardware, in the OS (operating system), and in programs and applications.

In hardware, memory management involves components that physically store data, such as RAM (random access memory) chips, memory caches, and flash-based SSDs (solid- state drives). In the OS, memory management involves the allocation (and constant reallocation) of specific memory blocks to individual programs as user demands change. At the application level, memory management ensures the availability of adequate memory for the objects and data structures of each running program at all times. Application memory management combines two related tasks, known as allocation and recycling.  When the program requests a block of memory, a part of the memory manager called the allocator assigns that block to the program.  When a program no longer needs the data in previously allocated memory blocks, those blocks become available for reassignment. This task can be done manually (by the programmer) or automatically (by the memory manager).

Swapping A process needs to be in memory for execution. But sometimes there is not enough main memory to hold all the currently active processes in a timesharing system. So, excess process are kept on disk and brought in to run dynamically. Swapping is the process of bringing in each process in main memory, running it for a while and then putting it back to the disk.

Contiguous Memory Allocation In contiguous memory allocation each process is contained in a single contiguous block of memory. Memory is divided into several fixed size partitions. Each partition contains exactly one process. When a partition is free, a process is selected from the input queue and loaded into it. The free blocks of memory are known as holes. The set of holes is searched to determine which hole is best to allocate.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 10

Operating System 2018

Memory Protection Memory protection is a phenomenon by which we control memory access rights on a computer. The main aim of it is to prevent a process from accessing memory that has not been allocated to it. Hence prevents a bug within a process from affecting other processes, or the operating system itself, and instead results in a segmentation fault or storage violation exception being sent to the disturbing process, generally killing of process.

Memory Allocation Memory allocation is a process by which computer programs are assigned memory or space. It is of three types : 1. First Fit: The first hole that is big enough is allocated to program. 2. Best Fit: The smallest hole that is big enough is allocated to program. 3. Worst Fit: The largest hole that is big enough is allocated to program.

2.1. Memory Management: Early Systems Single-User Configurations → Fixed Partitions → Dynamic Partitions → Relocatable Dynamic Partitions “Memory is the primary and fundamental power, without which there could be noother intellectual operation.”—Samuel Johnson (1709–1784)

Types of memory allocation schemes:  Single-user systems  Fixed partitions  Dynamic partitions  Relocatable dynamic partitions

2.1.1. Contiguous Memory Allocation Definition - What does Contiguous Memory Allocation mean? Contiguous memory allocation is a classical memory allocation model that assigns a process consecutive memory blocks (that is, memory blocks having consecutive addresses).

Contiguous memory allocation is one of the oldest memory allocation schemes. When a process needs to execute, memory is requested by the process. The size of the process is compared with the amount of contiguous main memory available to execute the process. If sufficient contiguous memory is found, the process is allocated memory to start its execution. Otherwise, it is added to a queue of waiting processes until sufficient free contiguous memory is available.

The contiguous memory allocation scheme can be implemented in operating systems with the help of two registers, known as the base and limit registers. When a process is

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 11

Operating System 2018

executing in main memory, its base register contains the starting address of the memory location where the process is executing, while the amount of bytes consumed by the process is stored in the limit register. A process does not directly refer to the actual address for a corresponding memory location. Instead, it uses a relative address with respect to its base register. All addresses referred by a program are considered as virtual addresses. The CPU generates the logical or virtual address, which is converted into an actual address with the help of the memory management unit (MMU). The base address register is used for address translation by the MMU. Thus, a physical address is calculated as follows:

Physical Address = Base register address + Logical address/Virtual address

The address of any memory location referenced by a process is checked to ensure that it does not refer to an address of a neighboring process. This processing security is handled by the underlying operating system.

One disadvantage of contiguous memory allocation is that the degree of multiprogramming is reduced due to processes waiting for free memory.

Single contiguous allocation Single allocation is the simplest memory management technique. All the computer's memory, usually with the exception of a small portion reserved for the operating system, is available to the single application. MS-DOS is an example of a system which allocates memory in this way. An embedded system running a single application might also use this technique.

A system using single contiguous allocation may still multitask by swapping the contents of memory to switch among users. Early versions of the Music operating system used this technique.

Advantages:  Very simple to implement Disadvantages:  Leads to uniprogramming  Leads to wastage of space  Leads to wastage of time (During any I/O operation CPU has to wait till I/O is finished)

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 12

Operating System 2018

2.1.2. Partitioned allocation Partitioned allocation divides primary memory into multiple memory partitions, usually contiguous areas of memory. Each partition might contain all the information for a specific job or task. Memory management consists of allocating a partition to a job when it starts and unallocating it when the job ends.

Partitioned allocation usually requires some hardware support to prevent the jobs from interfering with one another or with the operating system. The IBM System/360 used a lock-and-key technique. Other systems used base and bounds registers which contained the limits of the partition and flagged invalid accesses.

Partitions me be either static, that is defined at Initial Program Load (IPL) or boot time or by the computer operator, or dynamic, that is automatically created for a specific job. IBM System/360 Operating System Multiprogramming with a Fixed Number of Tasks (MFT) is an example of static partitioning, and Multiprogramming with a Variable Number of Tasks (MVT) is an example of dynamic.

Partitions may be relocatable using hardware typed memory, like the Burroughs Corporation B5500 or base and bounds registers like the PDP-10 or GE-635. Relocatable partitions are able to be compacted to provide larger chunks of physical memory.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 13

Operating System 2018

Some systems allow partitions to be swapped out to secondary storage to free additional memory. Early versions of IBM's Time Sharing Option (TSO) swapped users in and out of a single time-sharing partition.

2.1.2.1.Fixed Partitions Dividing the main memory into a set of non overlapping blocks is known as fixed partition. There are two types of fixed partitioning, they are: • Equal size partition The size of each block in fixed partition will be equal. Any process less than the size of partitioning can be loaded in the fixed partition of equal size.

• Unequal size partition The size of each block in fixed partition is varied where processes are assigned to the blocks where it fits exactly: in other words, processes may be queued to use the best available partition. In the unequal size partition compared to equal size partition, memory wastage is minimized, and may not give best throughput as some partitions may be unused. The unequal size partitions use two types of queues where processes are assigned to memory blocks. They are multiple queue and single queue.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 14

Operating System 2018

In multiple queues, each process is assigned to the smallest partition in which it fits and minimizes the internal fragmentation problem. In single queue, the process is assigned to the smallest available partition and the level of multiprogramming is increased.

Fixed size partitions suffer from two types of problems; they are overlays and internal fragmentation.

Overlays If a process is larger than the size of the partition then it suffers from overlaying problem in which only required information will be kept in memory. Overlays are extremely complex and time consuming task.

Internal fragmentation If process loaded is much smaller than any partition either equal or unequal, then it suffers from internal fragmentation in which memory is not used efficiently.

2.1.2.2.Dynamic Partitions Even though when we overcome some of the difficulties in variable sized fixed partitioning, dynamic partitioning require more sophisticated memory management techniques. The partitions used are of variable length. That is when a process is brought into main memory, it allocates exactly as much memory as it requires. Each partition may contain exactly one process. Thus the degree of multiprogramming is bound by the number of partitions. In this method when a partition is free a process is selected from the input queue and is loaded into the free partition. When the process terminates the partition becomes available for another process. This method was used by IBM's mainframe operating system, OS/MVT (Multiprogramming with variable number of tasks) and it is no longer in use now.

Let us consider the following scenario: Code: Process|Size (in kB)|Arrival time (in milli sec)|Service time (in milli sec) P1 |350 |0 |40 P2 |400 |10 |45 P3 |300 |30 |35 P4 |200 |35 |25

Figure below is showing the allocation of blocks in different stages by using dynamic partitioning method. That is the available main memory size is 1 MB. Initially the main

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 15

Operating System 2018

memory is empty except the operating system shown in Figure a. Then process 1 is loaded as shown in Figure b, then process 2 is loaded as shown in Figure c without the wastage of space and the remaining space in main memory is 146K it is free. Process 1 is swaps out shown in Figure d for allocating the other higher priority process. After allocating process 3, 50K whole is created it is called internal fragmentation, shown in Figure e. Now process 2 swaps out shown in Figure. Process 1 swaps in, into this block. But process 1 size is only 350K, this leads to create a whole of 50K shown in Figure.

Like this, it creates a lot of small holes in memory. Ultimately memory becomes more and more fragmented and it leads to decline memory usage. This is called ‗external fragmentation‘. To overcome external fragmentation by using a technique called "compaction". As the part of the compaction process, from time to time, operating system shifts the processes so that they are contiguous and this free memory is together creates a block. In Figure h compaction results in a block of free memory of length 246K. Advantages o Partitions are changed dynamically. o It does not suffer from internal fragmentation. Disadvantages  It is a time consuming process (i.e., compaction).  Wasteful of processor time, because from time to time to move a program from one region to another in main memory without invalidating the memory references.

2.1.2.3.Best-Fit versus First-Fit Allocation

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 16

Operating System 2018

First Fit In the first fit approach is to allocate the first free partition or hole large enough which can accommodate the process. It finishes after finding the first suitable free partition. Advantage Fastest algorithm because it searches as little as possible. Disadvantage The remaining unused memory areas left after allocation become waste if it is too smaller. Thus request for larger memory requirement cannot be accomplished.

Best Fit The best fit deals with allocating the smallest free partition which meets the requirement of the requesting process. This algorithm first searches the entire list of free partitions and considers the smallest hole that is adequate. It then tries to find a hole which is close to actual process size needed. Advantage Memory utilization is much better than first fit as it searches the smallest free partition first available. Disadvantage It is slower and may even tend to fill up memory with tiny useless holes.

Worst fit In worst fit approach is to locate largest available free portion so that the portion left will be big enough to be useful. It is the reverse of best fit. Advantage Reduces the rate of production of small gaps. Disadvantage If a process requiring larger memory arrives at a later stage then it cannot be accommodated as the largest hole is already split and occupied.

Buddy's System In buddy system, sizes of free blocks are in form of integral power of 2. E.g. 2, 4, 8, 16 etc. Up to the size of memory. When a free block of size 2k is requested, a free block from the list of free blocks of size 2k is allocated. If no free block of size 2k is available, the block of next larger size, 2k+1 is split in two halves called buddies to satisfy the request.

Example Let total memory size be 512KB and let a process P1, requires 70KB to be swapped in. As the hole lists are only for powers of 2, 128KB will be big enough. Initially no 128KB is there, nor are blocks 256KB. Thus 512KB block is split into two buddies of 256KB each, one is further split into two 128KB blocks and one of them is allocated to the process. Next P2 requires 35KB. Rounding 35KB up to a power of 2, a 64KB block is required.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 17

Operating System 2018

So when 128KB block is split into two 64KB buddies. Again a process P3(130KB) will be adjusted in the whole 256KB. After satisfying the request in this way when such block is free, the two blocks/buddies can be recombined to form the twice larger original block when it is second half buddy is also free.

Advantage Buddy system is faster. When a block of size 2k is freed, a hole of 2k memory size is searched to check if a merge is possible, whereas in other algorithms all the hole list must be searched.

Disadvantage It is often become inefficient in terms of memory utilization. As all requests must be rounded up to a power of 2, a 35KB process is allocated to 64KB, thus wasting extra 29KB causing internal fragmentation. There may be holes between the buddies causing external fragmentation.

Next fit Next fit is a modified version of first fit. It begins as first fit to find a free partition. When called next time it starts searching from where it left off, not from the beginning.

2.1.2.4. Relocatable Dynamic Partitions In relocatable dynamic partition, memory manager in operating system relocates the program, that is all empty blocks are gathered to form one single block of large memory enough to accommodate some or all of the jobs waiting in the queue. Consider the following example: Job Memory utilized Turnaround time Job1 100K 3 Job2 10K 1 Job3 30K 2 Job4 20K 1 Job5 25K 2 Job6 5K 1 Job7 25K 1 Job8 50K 2 Job9 90K 3 Job10 100K 3

Let us assume the memory size is 220k with 10k allocated to operating system programs. The above table gives the data of number of jobs, memory utilized by individual job and their respective turnaround time. There are 10 jobs to be loaded into memory. Initially with 220k of memory, we can load job1 to job6 with free memory of 20k.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 18

Operating System 2018

At first turnaround time, job2 of 10k, job4 of 20k, and job6 of 5k are completed leaving job 1, job 3, and job 5 as it is with free memory of 55k, in other words job1, job3, and job5 are still processing. Job 7 of 25k now enters into the memory partition leaving only 30k free memory where neither of the remaining jobs (job 8, job 9, and job 10) can accommodate.

At second turnaround time job3 of 30k, job5 of 25k, and job7 of 25k are completed leaving job 1 of 100k with free memory of 110k. Now job 8 of 50K is entered where 50k is allocated leaving 60K of free memory space where either job 9 or job 10 can accommodate.

Note: for job3 and job5 turnaround time is finished and at the same time turnaround time 1 of job 7 is also finished.

At third turnaround time, job1 of 100k is completed leaving free memory space of 160k. Job9 now can be allocated with 90k leaving remaining 70K of free memory where job10 cannot accommodate. Once job 8 finishes turnaround time of 2, it is completed leaving 120k of free memory space. Now job10 can be allocated with 100k of memory leaving 20K of free memory space. Process repeats until all the memory locations are freed leaving 10k allocated to operating system processes.

Diagrammatic representation of above example is shown below:

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 19

Operating System 2018

2.1.2.5. Deallocation Deallocation or deallocate is a process performed by a computer where a block of information is released from memory so that it may be used by a different program.

Deallocation of Memory. Deallocation of memory by the Operating System (OS) is a way to free the Random Access Memory (RAM) of finished processes and allocate new ones. ... It does so, with the help of a robust memory managementtechnique that handles all the allocations and deallocations of processes.

Memory allocated on the heap with new operator must be deallocated „manually‖, otherwise it will be marked as occupied until the program's termination, even if data which is stored there is not needed any more (or simply inaccessible). Memory can be deallocated (reclaimed) with the help of delete operator. Suppose we have allocated a single (non-array) object using new — the operator returned an address, which we assigned to a pointer variable pi of the appropriate pointer type. Exactly this address (more generally, an expression whose value is this address) must be used as argument of delete operator; for example: delete pi; will deallocate the memory allocated by the new. Very important: the variable pi will remain intact; it will not be „removed‖ or modified in any other way — only the memory it points to will be „removed‖ (released). Obviously, in place of pi, one could have used any expression as long as its value is the same as the value of pi.

It is illegal to use delete for an address which has not been returned by new.

Immediately after deallocation, the reclaimed segment of memory becomes available and may be used by the system for any purpose.

2.2. Virtual Memory Virtual memory is a memory management capability of an OS that uses hardware and software to allow a computer to compensate for physical memory shortages by temporarily transferring data from random access memory(RAM) to disk storage.

Virtual memory is a memory management capability of an OS that uses hardware and software to allow a computer to compensate for physical memory shortages by temporarily transferring data from random access memory (RAM) to disk storage. Virtual address space is increased using active memory in RAM and inactive memory in hard disk drives (HDDs) to form contiguous addresses that hold both the application and its data. Computers have a finite amount of RAM so memory can run out, especially when multiple programs run at the same time. A system using virtual memory can load larger programs or multiple programs running at the same time, allowing each one to operate as if it has infinite memory and without having to purchase more RAM.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 20

Operating System 2018

As part of the process of copying virtual memory into physical memory, the OS divides memory into page files or swap files that contain a fixed number of addresses. Each page is stored on a disk and when the page is needed, the OS copies it from the disk to main memory and translates the virtual addresses into real addresses.

Pros and cons of using virtual memory Among the primary benefits of virtual memory is its ability to handle twice as many addresses as main memory. It uses software to consume more memory by using the HDD as temporary storage while memory management units translate virtual memory addresses to physical addresses via the central processing unit. Programs use virtual addresses to store instructions and data; when a program is executed, the virtual addresses are converted into actual memory addresses.

Other advantages of virtual memory are that it frees applications from managing shared memory and saves users from adding more memory modules when RAM space runs out.

However, the use of virtual memory has its tradeoffs, particularly with speed. It's generally better to have as much physical memory as possible so programs work directly from RAM or physical memory. The use of virtual memory slows a computer because data must be mapped between virtual and physical memory, which requires extra hardware support for address translations.

In a virtualized computing environment, administrators can use virtual memory management techniques to allocate additional memory to a virtual machine (VM) that has run out of resources. Such virtualization management tactics can improve VM performance and management flexibility.

Benefits of having Virtual Memory 1. Large programs can be written, as virtual space available is huge compared to physical memory. 2. Less I/O required, leads to faster and easy swapping of processes.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 21

Operating System 2018

3. More physical memory available, as programs are stored on virtual memory, so they occupy very less space on actual physical memory.

2.2.1. Paged Memory Management Paged Memory Allocation : Paging is another solution for the fragmentation problem. In this each jobs address space divided into equal pieces called Pages. The memory is also divided into pieces of same size called Page Frames with the help of suitable hard ware mapping facility, any page can be placed into any Page Frame. The pages remain logically continuous but the corresponding Page Frames are not necessary continuous.

There is a separate register for each Job called Page Map Table these registers may be special hard ware registers or reserved section of the micro memory. If the page size is too large, it becomes a relocatable partitioned memory. If the page size is too small many page registers (PMT'S) are required which increases the cost of the computer systems. The paged memory allocation is shown in figure. In the next example address space of job1 is divided into two pages. Job2 is divided into three pages and Job3 consist of only one page we are assuming each page size is 1000 B there is a page map table for each Job which consists of page. Number and the location of that page in memory , there is mapping that takes place with each address i.e.., each address in the Job 's address space can be transferred into an address in the physical memory.

In the above example a Job may not be a multiple of 1000 B long. Then a portion of last page of that Job will be wasted. This is called Internal fragmentation.

Advantages : 1. It solves the fragmentation problem without physically moving the pages in memory. 2. This allows a higher degree of multiprogramming. 3. The compaction in relocatable partitioned allocation is elimated.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 22

Operating System 2018

Dis-Advantages : 1. Page address mapping hardware increase the cost of the computer system. 2. Extra core or extra registers needed for page map tables. 3. There is a possibility of internal fragmentation (or) page breakage may occur. 4. Some memory will still unused if the number of available page frames are not sufficient for the Job's page.

Implementation of Page Table  Page table is kept in main memory.  Page-table base register (PTBR) points to the page table.  Page-table length register (PRLR) indicates size of the page table.  In this scheme every data/instruction access requires two memory accesses. One for the page table and one for the data/instruction.  The two memory access problem can be solved by the use of a special fast-lookup hardware cache called associative memory or translation look-aside buffers (TLBs)

Page Table Structure  Hierarchical Paging  Break up the logical address space into multiple page tables.  A simple technique is a two-level page table.  Hashed Page Tables  Common in address spaces > 32 bits.  The virtual page number is hashed into a page table. This page table contains a chain of elements hashing to the same location.  Virtual page numbers are compared in this chain searching for a match. If a match is found, the corresponding physical frame is extracted.  Inverted Page Tables  One entry for each real page of memory.  Entry consists of the virtual address of the page stored in that real memory location, with information about the process that owns that page.  Decreases memory needed to store each page table, but increases time needed to search the table when a page reference occurs.  Use hash table to limit the search to one — or at most a few — page-table entries.

2.2.2. Demand Paging In virtual memory systems, demand paging is a type of swapping in which pages of data are not copied from disk to RAM until they are needed. In contrast, some virtual memory systems use anticipatory paging, in which the operating system attempts to anticipate which data will be needed next and copies it to RAM before it is actually required.

Demand paging is a type of swapping done in virtual memory systems. In demand paging, the data is not copied from the disk to the RAM until they are needed or being

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 23

Operating System 2018

demanded by some program. The data will not be copied when the data is already available on the memory. This is otherwise called a lazy evaluation because only the demanded pages of memory are being swapped from the secondary storage (disk space) to the main memory. In contrast during pure swapping, all the memory for a process is swapped from secondary storage to main memory during the process startup.

Demand Paging Working The demand paging working is based on a page table implementation. The page table maps logical memory to physical memory. The page table uses a bitwise operator to mark if a page is valid or invalid. A valid page is one that currently resides in main memory. An invalid page can be defined as the one that currently resides in secondary memory. When a process tries to access a page, the following will happen. 1) Attempt to access the page 2) The page is valid. Page processing instruction continues as normal. 3) If the page is an invalid one, then a page-fault trap occurs. 4) The memory reference is then checked to determine if it is a valid reference to a location on secondary memory or not. If not, the process is terminated (illegal memory access). Otherwise, the required page is paged in. 5) Now the disk operation to read the desired page into main memory is scheduled. 6) Finally, the instruction that was interrupted by the operating system trap is restarted. If you need any further assistance please contact our support department.

Advantages Demand paging, as opposed to loading all pages immediately:  Only loads pages that are demanded by the executing process.  As there is more space in main memory, more processes can be loaded reducing context switching time which utilizes large amounts of resources.  Less loading latency occurs at program startup, as less information is accessed from secondary storage and less information is brought into main memory.  As main memory is expensive compare to secondary memory, this technique helps significantly reduce the bill of material (BOM) cost in smart phones for example. Symbian OS had this feature. Disadvantages  Individual programs face extra latency when they access a page for the first time. So demand paging may have lower performance than anticipatory paging algorithms.  Programs running on low-cost, low-power embedded systems may not have a memory management unit that supports page replacement.  Memory management with page replacement algorithms becomes slightly more complex.  Possible security risks, including vulnerability to timing attacks; see Percival 2005 Cache Missing for Fun and Profit (specifically the virtual memory attack in section 2).

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 24

Operating System 2018

2.2.3. Page Replacement Policies and Concepts Basic to the implementation of virtual memory is the concept of demand paging. This means that the operating system, and not the programmer, controls the swapping of pages in and out of main memory as they are required by the active processes. When a non- resident page is needed by a process, the operating system must decide which resident page is to be replaced by the requested page. The part of the virtual memory which makes this decision is called the replacement policy.

There are many approaches to the problem of deciding which page to replace but the object is the same for all--the policy which selects the page that will not be referenced again for the longest time.

Examples: First In First Out (FIFO): The First In - First Out replacement policy chooses the page which has been in the memory the longest to be the one replaced. The illustration uses the yellow rectangles to illustrate the page frames in memory. A red rectangle represents a page fault (a new page was written into that frame). The reference string for this example is the diagonal sweep string from the discussion on reference strings. (You may review reference strings by clicking on the red star in the illustration.)

The illustration shows the number of page faults is reduced from 11 to 5 by the addition of the third page frame. Since 5 pages are referenced, this is the optimum condition. But the FIFO policy does not always work this well.

Least Recently Used (LRU): The Least Recently Used replacement policy chooses to replace the page which has not been referenced for the longest time. This policy assumes the recent past will approximate the immediate future. The operating system keeps track of when each page was referenced by recording the time of reference or by maintaining a stack of references.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 25

Operating System 2018

The Least Recently Used diagram above illustrates the LRU algorithm. The reference string used here is a part of the reference string for column matrix multiplication found in the reference string demonstration. Notice that the most recently accessed page is now represented by the top page rectangle. The rectangles do not represent specific page frames as they did in the FIFO diagram. Thus, each reference necessitating a page fault (shown in red) is now on the top row.

Further inspection will show that as more pages are allotted to the program the page references in each row do not change. Only the number of page faults changes. The set of pages in memory for n pages is thus a subset of the set of pages for n + 1 page frames. In fact, the diagram could be considered a STACK data structure with the depth of the stack representing the number of page frames. If a page is not on the stack (i.e. is found a depth greater than the number of page frames) then a page fault occurs. LRU and other page replacement policies that may be represented by a stack data structure are known as stack algorithms. [T1] [S1]

The notion that the LRU replacement policy can be represented as a stack leads the concept of the swapping function.

Last In First Out (LIFO): The page to be replaced is the one most recently loaded into the memory

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 26

Operating System 2018

Least Frequently Used (LFU): The page to be replaced is the one used least often of the pages currently in the memory

Optimal (OPT or MIN): The page to be replaced is the one that will not be used for the longest period of time. This algorithm requires future knowledge of the reference string which is not usually available. Thus, this policy is used for comparison studies

The anomalies associated with replacement policies like FIFO have led to the interest in the policies like LRU which do not suffer from such anomalies. They are known as stack algorithms.

2.2.4. Segmented Memory Allocation Segmented memory is a system of addressing computer memory, which may be physical or virtual and may be operating in real or protected mode.

The segmented memory system was used to expand the 64KB limit on first- generation flat address space. Computers made prior to segmented memory used a flat addressing system based on a four-digit hexadecimal code. With hexadecimal, the highest 4- digit number you can create is FFFF (or 65535), which equals 64KB.

Segmented memory addressing, the alternative to the flat scheme, is used in 16-bit systems such as MS-DOS Windows 3.1, to address 64KB segments of memory with an offset to specify within the segment.

The Intel 8086 processor generation was designed to address as much as 1MB of memory but was hampered by the limits of flat address space. Rather than redesign the entire memory system, Intel modified it to achieve the greater capacity through a two-part, compound 16-bit address.

The MMU (memory management unit) would then interpret the segment, as well as its offset, to find the physical address. Once the address was located, the MMU would enquire if the memory permissions allowed the request and, if they did, perform it.

Strictly speaking, flat address space used in 32-bit computing is actually segmented. However, the entire space is a single segment addressing the entirety of the 32-bit segment or 4GB memory space.

Segmented Memory Allocation : A well structured program consists of modules and also the relations between the modules or dessigned data a module is also known as a segment.A segment can be defined as logical group of information such as a subroutine or data area A segment may be a program of subprogram or a data base. A program and its data can be viewed as linked segment each segment has a name and off set. The physical addresses

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 27

Operating System 2018

assigned to the segments are maintained in a segment table the memory management technique that allocates main memory to segments is called segmentation.

Virtual memory can also be accomplished segmentation. Initially all the segments are stored secondary storage device. At the time of execution, there is a call statement that requires one segment when the required segment is not in the memory then the operating system searches the secondary storage device and bought into the memory. In this way the operation system links the calling segment to its coiller. The operation system must find a room for new segments by using compacting technique or by removing one of the segments in the memory.

Advantages : 1. It eliminates fragmantation. 2. It avoides virtual memory. 3. It helps in dynamic linking.

Dis-Advantages : 1.There is a difficulty in managing segments of different sizes on secondary storage device. 2.The maximum size of the main memory. 3.Memory compacting is required. 4.Increases the hardware cost.

Difference Between Paging And Segmentation : 1) A segment is a logical unit of information, visible the user's program and is of orbitary size. A page is a physical unit of information, invisible the user's program and is of fixed size. 2) In paging a new page is loaded in the memory by replacing one of the pages already in the memory where as in segmentation process the operating system makes a remove for incoming segment by compacting memory or by replaces a segment from the memory.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 28

Operating System 2018

2.2.5. Segmented Paged Memory Allocation In this memory allocation-method paging and segmentation can be combined to gain the advantage of both. This is done by dividing each segment into pages. By physically manupulating these pages the problems of compaction, secondary storage handling and limitation on segments size are removed. In this memory allocation scheme a word in main memory a logical address with three components.

1.Segment address 2.Page address 3.Line address

This scheme uses a segment table and a set of page tables. One page table is required for each segment the segment table register indicates the location and length of the current segment table. The segment table consists the each segment address and a pointer to the base of the corresponding page table the page table consists of the page numbers of a segment and page frame numbers used for loading the pages in the memory.

Initially all the system segments are stored in secondary storage device when a page is required for execution, if it is not in the memory then the operation system examines the segment table and page table and then the page is transferred from the secondary storage device to the main memory. If the memory is not available the required page is placed in the memory by replacing one of the previous pages.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 29

Operating System 2018

2.2.6. Demand Paged Memory Allocation Demand Paged Memory Allocation : In the demand paged memory allocation one programmer assumes infinite memory called virtual memory. In which the Job operates under demand.

Paging virtual memory is large in size then the available memory the demand paging allocation is shown in figure.

In demand pages memory allocation a particular page is swapped from the secondary storage device if it is required for execution.

In the above fig. Job address space consists of 10,000B of programs called page and we have only 3000B of memory available. This 10,000B program run in 3000B of memory by using demand paging.

The page map table consists of a page number, page frame number, status and judgement field. Initially the allocation algorithm places the first three pages of a program in the main memory. The job starts execution in one of these pages. Suppose in page O there is a transfer instruction to the location 9055. The hard ware mechanism uses 9 as index to the page lable that is page 9 is required in the execution. then the pagemap table is checked to find whether the page in the main memory job not if the required page is not in the main memory then the page fault occurs, then the hard ware generates interrept to the operating system then the operating system searches the secondary storage device for page 9 and brought into the memory by replacing one of the pages in the memory It may use a page remove algorithms like FIFO(First in first out) LRU(Least Recently Use) for removing a page. The decision which page has to replace it with judgement field in the page map table. It is desirable to keep highly used pages in the memory.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 30

Operating System 2018

Advantages : 1.Fragmentation is eliminated. 2.Large Virtual memory is available. 3.More efficient use of memory. 4.Demand paging is valuable in time sharing, systems.

Dis-Advantages : 1.Page address mapping hard ware increases the cost of the computer system 2.Extra memory, extra register needed for page map table.

2.2.7. Cache memory Cache memory, also called CPU memory, is high-speed static random access memory (SRAM) that a computer microprocessor can access more quickly than it can access regular random access memory (RAM). This memory is typically integrated directly into the CPU chip or placed on a separate chip that has a separate bus interconnect with the CPU. The purpose of cache memory is to store program instructions and data that are used repeatedly in the operation of programs or information that the CPU is likely to need next. The computer processor can access this information quickly from the cache rather than having to get it from computer's main memory. Fast access to these instructions increases the overall speed of the program.

As the microprocessor processes data, it looks first in the cache memory. If it finds the instructions or data it's looking for there from a previous reading of data, it does not have to perform a more time-consuming reading of data from larger main memory or other data storage devices. Cache memory is responsible for speeding up computer operations and processing.

Once they have been opened and operated for a time, most programs use few of a computer's resources. That's because frequently re-referenced instructions tend to be cached. This is why system performance measurements for computers with slower processors but larger caches can be faster than those for computers with faster processors but less cache space. Multi-tier or multilevel caching has become popular in server and desktop architectures, with different levels providing greater efficiency through managed tiering. Simply put, the less frequently certain data or instructions are accessed, the lower down the cache level the data or instructions are written.

Implementation and history Mainframes used an early version of cache memory, but the technology as it is known today began to be developed with the advent of microcomputers. With early PCs, processor performance increased much faster than memory performance, and memory became a bottleneck, slowing systems.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 31

Operating System 2018

In the 1980s, the idea took hold that a small amount of more expensive, faster SRAM could be used to improve the performance of the less expensive, slower main memory. Initially, the memory cache was separate from the system processor and not always included in the chipset. Early PCs typically had from 16 KB to 128 KB of cache memory.

With 486 processors, Intel added 8 KB of memory to the CPU as Level 1 (L1) memory. As much as 256 KB of external Level 2 (L2) cache memory was used in these systems. Pentium processors saw the external cache memory double again to 512 KB on the high end. They also split the internal cache memory into two caches: one for instructions and the other for data.

Processors based on Intel's P6 microarchitecture, introduced in 1995, were the first to incorporate L2 cache memory into the CPU and enable all of a system's cache memory to run at the same clock speed as the processor. Prior to the P6, L2 memory external to the CPU was accessed at a much slower clock speed than the rate at which the processor ran, and slowed system performance considerably.

Early memory cache controllers used a write-through cache architecture, where data written into cache was also immediately updated in RAM. This approached minimized data loss, but also slowed operations. With later 486-based PCs, the write-back cache architecture was developed, where RAM isn't updated immediately. Instead, data is stored on cache and RAM is updated only at specific intervals or under certain circumstances where data is missing or old.

Cache memory mapping Caching configurations continue to evolve, but cache memory traditionally works under three different configurations:  Direct mapped cache has each block mapped to exactly one cache memory location. Conceptually, direct mapped cache is like rows in a table with three columns: the data block or cache line that contains the actual data fetched and stored, a tag with all or part of the address of the data that was fetched, and a flag bit that shows the presence in the row entry of a valid bit of data.  Fully associative cache mapping is similar to direct mapping in structure but allows a block to be mapped to any cache location rather than to a prespecified cache memory location as is the case with direct mapping.  Set associative cache mapping can be viewed as a compromise between direct mapping and fully associative mapping in which each block is mapped to a subset of cache locations. It is sometimes called N-way set associative mapping, which provides for a location in main memory to be cached to any of "N" locations in the L1 cache.

Format of the cache hierarchy Cache memory is fast and expensive. Traditionally, it is categorized as "levels" that describe its closeness and accessibility to the microprocessor.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 32

Operating System 2018

L1 cache, or primary cache, is extremely fast but relatively small, and is usually embedded in the processor chip as CPU cache. L2 cache, or secondary cache, is often more capacious than L1. L2 cache may be embedded on the CPU, or it can be on a separate chip or coprocessor and have a high-speed alternative system bus connecting the cache and CPU. That way it doesn't get slowed by traffic on the main system bus. Level 3 (L3) cache is specialized memory developed to improve the performance of L1 and L2. L1 or L2 can be significantly faster than L3, though L3 is usually double the speed of RAM. With multicore processors, each core can have dedicated L1 and L2 cache, but they can share an L3 cache. If an L3 cache references an instruction, it is usually elevated to a higher level of cache.

In the past, L1, L2 and L3 caches have been created using combined processor and motherboard components. Recently, the trend has been toward consolidating all three levels of memory caching on the CPU itself. That's why the primary means for increasing cache size has begun to shift from the acquisition of a specific motherboard with different chipsetsand bus architectures to buying a CPU with the right amount of integrated L1, L2 and L3 cache.

Contrary to popular belief, implementing flash or more dynamic RAM (DRAM) on a system won't increase cache memory. This can be confusing since the terms memory caching (hard disk buffering) and cache memory are often used interchangeably. Memory caching, using DRAM or flash to buffer disk reads, is meant to improve storage I/O by caching data that is frequently referenced in a buffer ahead of slower magnetic disk or tape. Cache memory, on the other hand, provides read buffering for the CPU.

Specialization and functionality In addition to instruction and data caches, other caches are designed to provide specialized system functions. According to some definitions, the L3 cache's shared design makes it a specialized cache. Other definitions keep instruction caching and data caching separate, and refer to each as a specialized cache.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 33

Operating System 2018

Translation lookaside buffers (TLBs) are also specialized memory caches whose function is to record virtual address to physical address translations.

Still other caches are not, technically speaking, memory caches at all. Disk caches, for instance, can use RAM or flash memory to provide data caching similar to what memory caches do with CPU instructions. If data is frequently accessed from disk, it is cached into DRAM or flash-based silicon storage technology for faster access time and response.

Specialized caches are also available for applications such as web browsers, databases, network address binding and client-side Network File System protocol support. These types of caches might be distributed across multiple networked hosts to provide greater scalability or performance to an application that uses them.

Locality The ability of cache memory to improve a computer's performance relies on the concept of locality of reference. Locality describes various situations that make a system more predictable, such as where the same storage location is repeatedly accessed, creating a pattern of memory access that the cache memory relies upon. There are several types of locality. Two key ones for cache are temporal and spatial. Temporal locality is when the same resources are accessed repeatedly in a short amount of time. Spatial locality refers to accessing various data or resources that are in close proximity to each other.

Cache vs. main memory DRAM serves as a computer's main memory, performing calculations on data retrieved from storage. Both DRAM and cache memory are volatile memories that lose their contents when the power is turned off. DRAM is installed on the motherboard, and the CPU accesses it through a bus connection.

DRAM is usually about half as fast as L1, L2 or L3 cache memory, and much less expensive. It provides faster data access than flash storage, hard disk drives (HDDs) and tape storage. It came into use in the last few decades to provide a place to store frequently accessed disk data to improve I/O performance.

DRAM must be refreshed every few milliseconds. Cache memory, which also is a type of random access memory, does not need to be refreshed. It is built directly into the CPU to give the processor the fastest possible access to memory locations, and provides nanosecond speed access time to frequently referenced instructions and data. SRAM is faster than DRAM, but because it's a more complex chip, it's also more expensive to make.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 34

Operating System 2018

Cache vs. virtual memory A computer has a limited amount of RAM and even less cache memory. When a large program or multiple programs are running, it's possible for memory to be fully used. To compensate for a shortage of physical memory, the computer's operating system (OS) can create virtual memory.

To do this, the OS temporarily transfers inactive data from RAM to disk storage. This approach increases virtual address space by using active memory in RAM and inactive memory in HDDs to form contiguous addresses that hold both an application and its data. Virtual memory lets a computer run larger programs or multiple programs simultaneously, and each program operates as though it has unlimited memory.

Where virtual memory fits in the memory hierarchy.

In order to copy virtual memory into physical memory, the OS divides memory into pagefiles or swap files that contain a certain number of addresses. Those pages are stored on a disk and when they're needed, the OS copies them from the disk to main memory and translates the virtual addresses into real addresses.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 35

Operating System 2018

Unit – III Processor Management 3. Introduction Process management is an integral part of any modern-day operating system (OS). The OS must allocate resources to processes, enable processes to share and exchange information, protect the resources of each process from other processes and enable synchronization among processes.

The heart of managing the processor comes down to two related issues:  Ensuring that each process and application receives enough of the processor's time to function properly  Using as many processor cycles as possible for real work

The basic unit of software that the operating system deals with in scheduling the work done by the processors either a process or a thread, depending on the operating system.

It's tempting to think of a process as an application, but that gives an incomplete picture of how processes relate to the operating system and hardware. The application you see (word

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 36

Operating System 2018

processor, spreadsheet or game) is, indeed, a process, but that application may cause several other processes to begin, for tasks like communications with other devices or other computers. There are also numerous processes that run without giving you direct evidence that they ever exist. For example, Windows XP and UNIX can have dozens of background processes running to handle the network, memory management, disk management, virus checks and so on.

A process, then, is software that performs some action and can be controlled -- by a user, by other applications or by the operating system.

It is processes, rather than applications, that the operating system controls and schedules for execution by the CPU. In a single-tasking system, the schedule is straightforward. The operating system allows the application to begin running, suspending the execution only long enough to deal with interrupts and user input. Interrupts are special signals sent by hardware or software to the CPU. It's as if some part of the computer suddenly raised its hand to ask for the CPU's attention in a lively meeting. Sometimes the operating system will schedule the priority of processes so that interrupts are masked -- that is, the operating system will ignore the interrupts from some sources so that a particular job can be finished as quickly as possible. There are some interrupts (such as those from error conditions or problems with memory) that are so important that they can't be ignored. These non-maskable interrupts (NMIs) must be dealt with immediately, regardless of the other tasks at hand.

While interrupts add some complication to the execution of processes in a single-tasking system, the job of the operating system becomes much more complicated in a multi-tasking system. Now, the operating system must arrange the execution of applications so that you believe that there are several things happening at once. This is complicated because the CPU can only do one thing at a time. Today's multi-core processors and multi-processor machines can handle more work, but each processor core is still capable of managing one task at a time.

In order to give the appearance of lots of things happening at the same time, the operating system has to switch between different processes thousands of times a second. Here's how it happens:  A process occupies a certain amount of RAM. It also makes use of registers, stacks and queues within the CPU and operating-system memory space.  When two processes are multi-tasking, the operating system allots a certain number of CPU execution cycles to one program.  After that number of cycles, the operating system makes copies of all the registers, stacks and queues used by the processes, and notes the point at which the process paused in its execution.  It then loads all the registers, stacks and queues used by the second process and allows it a certain number of CPU cycles.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 37

Operating System 2018

 When those are complete, it makes copies of all the registers, stacks and queues used by the second program, and loads the first program.

3.1. About Multi-Core Technologies In consumer technologies, multi-core is usually the term used to describe two or more CPUs working together on the same chip. Also called multicore technology, it is a type of architecture where a single physical processor contains the core logic of two or more processors. These processors are packaged into a single integrated circuit (IC). These single integrated circuits are called a die. Multi-core can also refer to multiple dies packaged together. Multi-core enables the system to perform more tasks with a greater overall system performance. Multi-core technology can be used in desktops, mobile PCs, servers and workstations. Contrast with dual-core, a single chip containing two separate processors (execution cores) in the same IC.

How It Works The multi-core processor technology was conceptualized and has revolved around the idea of being able to make parallel computing possible. Parallel computing could dramatically increase the speed, efficiency and performance of computers by simply putting 2 or more Central Processing Units (or CPU) in only one chip. This would ultimately minimize the power and heat consumption of the system while still being able to greatly boost system performance without sacrificing energy consumption limits. This would give more performance with less or with the same amount of energy.

The multi-core technology would also enable users to do more tasks at the same time. Since more computing workloads could be done at the same time, manufacturers such as Intel and AMD could focus more on increasing computing and processing performance without increasing clock speeds and thus avoid the need for consuming more energy.

Multi-core processors work at their full potential if they are used with multi-threaded programs or software. Multithreaded software could include applications and most importantly operating systems that have the ability to split tasks and commands into a set of separate workloads that could then be processed and run simultaneously on each of the cores present. This means more work is done in less time.

Future Implications With Intel and AMD, the future of computing is clearly seen in favor of the multi-core utilization trend. With an increase of multithreaded applications seen at hand in the near future, the number of computers utilizing multi- core processors (dual cores, quad cores, etc.) is expected to rise. Experts say that the number of cores that could be integrated in one chip could increase over time as their physical size and energy consumption declines.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 38

Operating System 2018

Applications Multi-core technology is useful especially in very demanding applications and tasks such as video editing, encoding and 3D gaming. The full effect and the advantage of having a multi-core computer, however, is felt only when it is used together with a multithreading operating system such as Windows XP or Linuxand with applications that are capable of multithreading.

Even when applications are not multithreaded, it is possible for a multithreaded operating system to properly delegate tasks to multiple cores helping the system manage the workload on each core. Applications that are large resource consumers, such as 3D games, or office suites with lots of middleware will be less effective, however, since all tasks related to those specific applications will have to be delegated to a single core for proper operation.

It is expected that most application development efforts will focus on multithreaded models, making multi-core systems more and more desirable.

Issues As of now, most computer applications are not yet capable of splitting their tasks into workloads that could be separately processed on each core. It would still take time before the software industry catches up with computer processor manufacturers and create applications with multithreading capabilities.

Moreover, even the programs and operating systems that have the ability to split tasks into several threads are still far from being able to maximize the multi-core technology's potential. Experts claim that the structure of software and applications that exist today and the design of most computer hardware are made for multiple homogeneous cores so they're really not made for optimal usage of multi-core technology.

Many applications are coded without resource consumption in mind, as with many of the most popular office packages and 3D games, which will not allow the multi-core system to assist in workload management.

3.2.Job Scheduling Versus Process Scheduling

3.2.1. Definition - What does Job Scheduling mean? Job scheduling is the process of allocating system resources to many different tasks by an operating system (OS). The system handles prioritized job queues that are awaiting CPU time and it should determine which job to be taken from which queue and the amount of time to be allocated for the job. This type of scheduling makes sure that all jobs are carried out fairly and on time.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 39

Operating System 2018

Most OSs like Unix, Windows, etc., include standard job-scheduling abilities. A number of programs including database management systems (DBMS), backup, enterprise resource planning (ERP) and business process management (BPM) feature specific job- scheduling capabilities as well.

Job scheduling is performed using job schedulers. Job schedulers are programs that enable scheduling and, at times, track computer "batch" jobs, or units of work like the operation of a payroll program. Job schedulers have the ability to start and control jobs automatically by running prepared job-control-language statements or by means of similar communication with a human operator. Generally, the present-day job schedulers include a graphical user interface (GUI) along with a single point of control.

Organizations wishing to automate unrelated IT workload could also use more sophisticated attributes from a job scheduler, for example:

 Real-time scheduling in accordance with external, unforeseen events  Automated restart and recovery in case of failures  Notifying the operations personnel  Generating reports of incidents  Audit trails meant for regulation compliance purposes

In-house developers can write these advanced capabilities; however, these are usually offered by providers who are experts in systems-management software. In scheduling, many different schemes are used to determine which specific job to run. Some parameters that may be considered are as follows:

 Job priority  Availability of computing resource  License key if the job is utilizing a licensed software  Execution time assigned to the user  Number of parallel jobs permitted for a user  Projected execution time  Elapsed execution time  Presence of peripheral devices  Number of cases of prescribed events

A job scheduler is a computer application for controlling unattended background program execution (commonly called batch processing). Synonyms are batch system, Distributed Resource Management System (DRMS), and Distributed Resource Manager (DRM). Today's job schedulers, often termed workload automation, typically provide a graphical user interface and a single point of control for definition and monitoring of background executions in a distributed network of computers. Increasingly, job schedulers are required to orchestrate the integration of real-time business activities with traditional background IT

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 40

Operating System 2018

processing across different operating system platforms and business application environments.

Job scheduling should not be confused with process scheduling, which is the assignment of currently running processes to CPUs by the operating system.

Over view Basic features expected of job scheduler software include:  interfaces which help to define workflows and/or job dependencies  automatic submission of executions  interfaces to monitor the executions  priorities and/or queues to control the execution order of unrelated jobs

If software from a completely different area includes all or some of those features, this software is considered to have job scheduling capabilities.

Most operating systems (such as Unix and Windows) provide basic job scheduling capabilities, for example: cron. Web hosting services provide job scheduling capabilities through a control panel or a webcron solution. Many programs such as DBMS, backup,ERPs, and BPM also include relevant job-scheduling capabilities. Operating system ("OS") or point program supplied job-scheduling will not usually provide the ability to schedule beyond a single OS instance or outside the remit of the specific program. Organizations needing to automate unrelated IT workload may also leverage further advanced features from a job scheduler, such as:

 real-time scheduling based on external, unpredictable events  automatic restart and recovery in event of failures  alerting and notification to operations personnel  generation of incident reports  audit trails for regulatory compliance purposes

These advanced capabilities can be written by in-house developers but are more often provided by suppliers who specialize in systems-management software.

Main Concept: There are many concepts that are central to almost every job scheduler implementation and that are widely recognized with minimal variations:

 Jobs  Dependencies  Job Streams  Users

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 41

Operating System 2018

Beyond the basic, single OS instance scheduling tools there are two major architectures that exist for Job Scheduling software.

 Master/Agent architecture — the historic architecture for Job Scheduling software. The Job Scheduling software is installed on a single machine (Master), while on production machines only a very small component (Agent) is installed that awaits commands from the Master, executes them, then returns the exit code back to the Master.  Cooperative architecture — a decentralized model where each machine is capable of helping with scheduling and can offload locally scheduled jobs to other cooperating machines. This enables dynamic workload balancing to maximize hardware resource utilization and high availability to ensure service delivery.

History An important niche for job schedulers is managing the job queue for a cluster of computers. Typically, the scheduler will schedule jobs from the queue as sufficient resources (cluster nodes) become idle. Some widely used cluster batch systems are Oracle Grid Engine,Portable Batch System, LoadLeveler, Condor, OAR and Simple Linux Utility for Resource Management.

Job Scheduling has a long history. Job Schedulers have been one of the major components of IT infrastructure since the early mainframe systems. At first, stacks of punched cards were processed one after the other, hence the term ―batch processing.‖

From a historical point of view, we can distinguish two main eras about Job Schedulers: 1. The mainframe era . Job Control Language (JCL) on IBM mainframes. Initially based on JCL functionality to handle dependencies, this era is typified by the development of sophisticated scheduling solutions forming part of the systems management and automation toolset on the mainframe. 2. The open systems era . Modern schedulers on a variety of architectures and operating systems. With standard scheduling tools limited to such asCron, the need for mainframe standard job schedulers has grown with the increased adoption of distributed computing environments.

In terms of the type of scheduling there are also distinct eras:  Batch processing - the traditional date and time based execution of background tasks based on a defined period during which resources were available for batch processing (the batch window). In effect the original mainframe approach transposed onto the open systems environment.  Event-driven process automation - where background processes cannot be simply run at a defined time, either because the nature of the business demands that workload is based on the occurrence of external events (such as the arrival of an order from a

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 42

Operating System 2018

customer or a stock update from a store branch) or because there is no / insufficient batch window.  Service Oriented job scheduling - recent developments in Service Oriented Architecture (SOA) have seen a move towards deploying job scheduling as a reusable IT infrastructure service that can play a role in the integration of existing business application workload with new Web Services based real-time applications.

Scheduling Various schemes are used to decide which particular job to run. Parameters that might be considered include:  Job priority  Compute resource availability  License key if job is using licensed software  Execution time allocated to user  Number of simultaneous jobs allowed for a user  Estimated execution time  Elapsed execution time  Availability of peripheral devices  Occurrence of prescribed events

Describe different job scheduling in operating systems. Job scheduling schedules or decides which process will get to acquire the resource based on some parameters. FIFO- The process that comes first is executed first. Shortest job First- The time taken to complete the job of all processes is computed and the shortest length process is executed first. Round Robin- Each process gets a time ―share‖ for running and is later prevented to get the next process running. Priority scheduling- here, the process on highest priority gets the resource.

3.2.2. Process Scheduling

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 43

Operating System 2018

If there are several runnable jobs, the operating system has to decide which job to run next, a process known as Process Scheduling.

In olden days, when computers ran batch jobs, this was not an issue. The computer operator simply submitted the jobs in the order that they were delivered to him or her, and each job ran to completion. We can call this algorithm First come first served, or FIFO (first in first out).

However, even this primitive system had problems. Suppose there are five jobs waiting to be run. Four of the five jobs will take about ten seconds each to run, and one will take ten minutes, but the ten minute job was submitted first. In a FIFO system, the four fast jobs will all be held up for a long time by a large job that happened to be delivered first.

In a batch system, this was not serious since jobs were never interactive. However, if we knew ahead of time how long each job would take, we could maximize throughput. In fact, some computer centers in the '60s could actually do this. When a user submitted a job, he or she was also asked to specify an estimated run time. The operator would then allow a job to run only for that amount of time (or perhaps a few seconds longer). This was important, because even then, programmers could write programs with infinite loops. If a program exceeded its estimated run time, the operator killed it.

This permitted the operator to run jobs using a shortest job first algorithm. As the name implies, instead of running jobs in the order that they are delivered, the operator would search through all available jobs and run that job which had the shortest run time. This is provably the fastest job scheduling algorithm. A simple example will demonstrate this.

Suppose four jobs arrived at about the same, but not exactly the same, time. We happen to know exactly how long each job will take. Here are the run times of the four jobs, in the order that they arrived. Job One 25 Job Two 10 Job Three 20 Job Four 15 If the jobs are run with a FIFO algorithm, here are the total times to completion for each of the four jobs (assuming that it takes no time to load a job). Job One 25 Job Two 35 Job Three 55 Job Four 70 The average time to completion was 46.25 seconds ((25 + 35 + 55 + 70) / 4). If the jobs are run shortest job first, (Job Two, Job Four, Job Three, Job One) here are the total times to completion of the four jobs.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 44

Operating System 2018

Job One 70 Job Two 10 Job Three 45 Job Four 25 It still takes 70 seconds to run all four jobs, but the average time to completion for a job was 37.5 seconds ((70 + 10 + 45 + 25) / 4). Process scheduling on a modern multiprogramming operating system is far more complex. Recall our state diagram for the states of a process

3.2.2.1. Types of process scheduling The OS has to make decisions at three levels: 1. long term scheduling: When a process is started, it is placed in the state new. The necessary data structures are created ( in the memory assigned to the kernel), but no memory is assigned to the process itself. At this time the OS has to decide if the process is loaded into virtual memory. This means that the process resides on disk or in main memory. On an interactive system ( which we are using) this scheduling decision is very simple: every user has a maximal amount of programs they can start. 2. medium term scheduling: is part of swapping. 3. short term scheduling: is discussed in this chapter. At this level the OS decides which process to assign to the processor . This means a change from the ready to the running state. The part of the OS which executes this transition is called the dispatcher. This type of scheduling is executed most frequently.

Taking into account the states of a process, and the time scale at which state transition occur, we can immediately recognize that  dispatching affects processes  running  ready  blocked  the medium term scheduling affects processes  ready-suspended  blocked-suspended  the long term scheduling affects processes  new  exited

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 45

Operating System 2018

Long term scheduling obviously controls the degree of multiprogramming in multitasking systems, following certain policies to decide whether the system can honour a new job submission or, if more than one job is submitted, which of them should be selected. The need for some form of compromise between degree of multiprogramming and throughput seems evident, especially when one considers interactive systems.

The higher the number of processes, in fact, the smaller the time each of them may control CPU for, if a fair share of responsiveness is to be given to all processes. Moreover we have already seen that a too high number of processes causes waste of CPU time for system housekeeping chores (trashing in virtual memory systems is a particularly nasty example of this). However, the number of active processes should be high enough to keep the CPU busy servicing the payload (i.e. the user processes) as much as possible, by ensuring that - on average - there always be a sufficient number of processes not waiting for I/O.

Simple policies for long term scheduling are  Simple First Come First Served (FCFS): it's essentially a FIFO scheme. All job requests (e.g. a submission of a batch program, or an user trying to log in in a time shared system) are honoured up to a fixed system load limit, further requests being refused tout court, or enqueued for later processing.  Priority schemes. Note that in the context of long term scheduling ``priority'' has a different meaning than in dispatching: here it affects the choice of a program to be entered the system as a process, there the choice of which ready process process should be executed.

3.3.Process Scheduling Policies Job Scheduler implements the following scheduling policies:  Priority-based first come, first served scheduling  Backfilling  Exclusive scheduling

Priority-based first come, first served Priority-based first come, first served (FCFS) scheduling is a combination of FCFS and priority-based scheduling. Using priority-based FCFS scheduling, the scheduler places a job into a higher or lower priority group depending on the job's priority setting, but always places that job at the end of the queue in that priority group because it is the last submitted job.

Backfilling Backfilling maximizes node utilization by allowing a smaller job or jobs lower in the queue to run ahead of a job waiting at the top of the queue, as long as the job at the top is not delayed as a result.

When a job reaches the top of the queue, a sufficient number of nodes may not be available to meet its minimum processors requirement. When this happens, the job reserves any nodes

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 46

Operating System 2018

that are immediately available and waits for the job that is currently running to complete. Backfilling then utilizes the reserved idle nodes as follows:  Based on the run time specified for the job that is currently running, a start time for the waiting job is established.  The start time is used to define a backfill window of nodes (n)x time (t). For example, four nodes idle for 15 minutes would create a 4 x 15 backfill window.  Job Scheduler searches for the first job in the queue that can complete within the backfill window. For example, a job that requires a minimum of eight processors (four nodes, assuming dual-processor nodes) and has a run time of 10 minutes would fit the 4 x 15 window exactly.  If a job is found that fits the window, it is activated and run ahead of the job waiting at the top of the queue.

Exclusive scheduling Exclusive scheduling restricts the resources of a node to a job or task. In both cases, depending on its default setting, exclusivity can be turned off to enable sharing or turned on to prevent sharing.

Job exclusivity By default, a job has exclusive use of the nodes reserved by it. This can produce idle reserved processors on a node: processors that are not used by the job but are also not available to other jobs. By turning off the exclusive property, the user allows the job to share its unused processors with other jobs that have also been set to nonexclusive. Therefore, nonexclusivity is a reciprocal agreement among participating jobs, allowing each to take advantage of the other's unused processors.

Task nonexclusivity By default, a task has nonexclusive use of the node it runs on. Otherwise the node would always run as if it had only one processor. The exclusive option is provided for exceptional cases, like a task that reboots the node.

Resource sorting To allocate nodes, the Job Scheduler sorts the candidate nodes by memory size, and then, within each size group, by processor speed. The nodes are then allocated in the resulting order.

Run time Job and Task Management Job Scheduler is responsible for run time management of the job and its tasks. This includes the following functions:  Enforcement of job and task run time properties  State (status) transition

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 47

Operating System 2018

3.4. Process Scheduling Algorithms First come first serve(FCFS), Shortest job first(SJF), and Shortest remaining time first(SRTF) are used in batch system. Round robin(RR), Highest response ratio next(HRRN), Priority scheduling with multilevel queue, and priority with multilevel feedback queue are used in interactive system.

First Come First Serve (FCFS) scheduling algorithm: FCFS is implemented using Queue and works as first come first serve manner. Processes executes based on their order of arrivals. FCFS algorithm is simple to implement but it causes Convoy Effect. If first process has too long burst time, so other shorter process has more waiting time to execute, this effect called as Convoy Effect. Example: Consider the following table:

Process no. Arrival Time Burst Time P1 0 6 P2 2 1 P3 4 4 P4 5 3 Find the average waiting time and average turn arround time using FCFS algorithm? Solution: Using FCFS process scheduling algorithm, gantt chart is:

Therefore,

Waiting Turn Around Completion Process Arrival Burst Time Time Time No. Time Time 6 - 6 = 0 6 - 0 = 6 6 P1 0 6 5 - 1 = 4 7 - 2 = 5 7 P2 2 1 7 - 4 = 3 11 - 4 = 7 11 P3 4 4 9 - 3 = 6 14 - 5 = 9 14 P4 5 3

Average Turn Arround Time = (6 + 5 + 7 + 9) / 4 = 6.75 Average Waiting Time = (0 + 4 + 3 + 6) / 4 = 3.25

Shortest Job First Scheduling Algorithm(non- preemptive): SJF is based on prediction of burst time. SJF schedules a process with smallest burst time. In simple words, this algorithms executes process with their increasing order of CPU burst time. If all processes are having same CPU burst time then this works as FCFS algorithm. SJF minimizes average waiting time, however it‘s hard to predict CPU burst time in advance.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 48

Operating System 2018

Example: Consider the following table:

Process no. Arrival Time Burst Time P1 0 6 P2 2 1 P3 4 4 P4 5 3 Find the average waiting time and average turn arround time using SJF(non-preemptive) algorithm? Solution: Using SJF(non-preemptive) algorithm, gantt chart is:

Therefore,

Waiting Turn around Completion Process Arrival Burst Time Time Time No. Time Time 6 - 6 = 0 6 - 0 = 6 6 P1 0 6 5 - 1 = 4 7 - 2 = 5 7 P2 2 1 9 - 4 = 5 14 - 5 = 9 14 P3 5 4 4 - 3 = 1 10 - 6 = 4 10 P4 6 3 So, Average Turn arround time = (6 + 5 + 9 + 4) / (4) = 6 Average Waiting time = (0 + 4 + 5 + 1) / (4) = 2.5 Shortest Remaining Time First(SRTF) algorithm: This is preemptive version of shortest job first algorithm. It‘s minimize average turn arround time. If all processes are arrived at same time, then it works as SJF. Example: Consider the following table:

Process no. Arrival Time Burst Time P1 0 6 P2 2 1 P3 4 4 P4 5 3 Find the average waiting time and average turn arround time using SRTF(preemptive) algorithm? Solution: Using SRTF(non-preemptive) algorithm, gantt chart is:

Therefore,

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 49

Operating System 2018

Waiting Turn around Completion Process Arrival Burst Time Time Time No. Time Time 7 - 6 = 1 7 - 0 = 7 7 P1 0 6 1 - 1 = 0 3 - 2 = 1 3 P2 2 1 9 - 4 = 5 14 - 5 = 9 14 P3 5 4 4 - 3 = 1 10 - 6 = 4 10 P4 6 3 So, Average Turn arround time = (7 + 1 + 9 + 4) / (4) = 5.25 Average Waiting time = (1 + 0 + 5 + 1) / (4) = 1.75

Round Robin(RR) Process Scheduling Algorithm: This is preemptive version of FCFS algorithm based on time quantum. Very large time quantum makes Round Robin as FCFS algorithm. It minimizes average response time. It has circular queue to hold processes to be executed next.

Example: Consider the following table: Process no. Arrival Time Burst Time P1 0 6 P2 2 1 P3 4 4 P4 5 3 Find the average waiting time and average turn arround time using RR(Round Robin) algorithm with Time Quantum size 2? Solution: Using round robin algorithm with time quantum size 2, ready queue and gantt chart are:

Ready Queue: P1, P2, P1, P3, P1, P4, P3, P4 Gantt chart is:

Therefore,

Waiting Turn around Completion Process Arrival Burst Time Time Time No. Time Time 9 - 6 = 3 9 - 0 = 9 9 P1 0 6 1 - 1 = 0 3 - 2 = 1 3 P2 2 1 8 - 4 = 4 13 - 5 = 8 13 P3 5 4 8 - 3 = 5 14 - 6 = 8 14 P4 6 3 So, Average Turn arround time = (9 + 1 + 8 + 8) / (4) = 6.5

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 50

Operating System 2018

Average Waiting time = (3 + 0 + 4 + 5) / (4) = 3

Priority based (Non-preemptive) Process Scheduling: Priority can be internal or external and static or dynamic. This algorithm selects process with highest priority to execute. Example: Consider the following table: Process no. Arrival Time Burst Time Priority P1 0 6 2 P2 2 1 4 (Lowest) P3 4 4 1 (Highest) P4 5 3 3 Find the average waiting time and average turn arround time using Priority(Non-preemptive) algorithm? Solution: Using Priority(non-preemptive) algorithm, gantt chart is:

Therefore,

Turn around Completion Process Arrival Burst Waiting Time Priority Time Time No. Time Time 6 - 6 = 0 6 - 0 = 6 6 P1 0 6 2 4 12 - 1 = 11 14 - 2 = 12 14 P2 2 1 (Lowest) 1 5 - 4 = 1 10 - 5 = 5 10 P3 5 4 (highest) 7 - 3 = 4 13 - 6 = 7 13 P4 6 3 3

So, Average Turn arround time = (6 + 12 + 5 + 7) / (4) = 7.5 Average Waiting time = (0 + 11 + 1 + 4) / (4) = 4

Priority based (preemptive) Process Scheduling: This algorithm selects process with highest priority to execute and it‘s preempted lower priority process. Example: Consider the following table:

Process no. Arrival Time Burst Time Priority P1 0 6 2 P2 2 1 4 (Lowest) P3 4 4 1 (Highest) P4 5 3 3

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 51

Operating System 2018

Find the average waiting time and average turn arround time using Priority(Preemptive) algorithm? Solution: Using Priority(Preemptive) algorithm, gantt chart is:

Therefore,

Waiting Turn around Completion Process Arrival Burst Priority Time Time Time No. Time Time 10 - 6 = 4 10 - 0 = 10 10 P1 0 6 2 4 12 - 1 = 11 14 - 2 = 12 14 P2 2 1 (Lowest) 1 4 - 4 = 0 9 - 5 = 4 9 P3 5 4 (highest) 7 - 3 = 4 13 - 6 = 7 13 P4 6 3 3

So, Average Turn arround time = (10 + 12 + 4 + 7) / (4) = 8.25 Average Waiting time = (4 + 11 + 0 + 4) / (4) = 4.75

Highest Response Ratio Next (HRRN) Scheduling: It is non-preemptive scheduling algorithm. This select the process with highest ration of response and burst time. It minimizes the turn around time. Response Time = (Latest response time) - (Arrival Time) Response Ratio = Response time(or Turn around time) / Burst Time = (WT + BT) / BT Example: Consider the following table: Process no. Arrival Time Burst Time P1 0 6 P2 2 1 P3 4 4 P4 5 3 Find the average waiting time and average turn around time using HRRN algorithm? Solution: Using HRRN algorithm, response ratio for first term (only one process ready to execute): Response ratio (RR) = (WT1 + BT1) / (BT1) = (0 + 6)/6 = 1

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 52

Operating System 2018

Response ratio for second term: RR2 = (4 + 1)/1 = 5 RR3 = (2 + 4)/4 = 1.5 RR4 = (1 + 3)/3 = 1.33

HRRN algorithm selects process with highest RR P2:

Response ratio for third term: RR3 = (3 + 4)/4 = 1.75 RR4 = (2 +3)/3 = 1.67

HRRN algorithm selects process with highest RR P3:

At the last, HRRN selects final process to executes:

Therefore,

Waiting Turn Around Completion Process Arrival Burst Time Time Time No. Time Time 6 - 6 = 0 6 - 0 = 6 6 P1 0 6 5 - 1 = 4 7 - 2 = 5 7 P2 2 1 7 - 4 = 3 11 - 4 = 7 11 P3 4 4 9 - 3 = 6 14 - 5 = 9 14 P4 5 3 Average Turn Arround Time = (6 + 5 + 7 + 9) / 4 = 6.75 Average Waiting Time = (0 + 4 + 3 + 6) / 4 = 3.25

Multilevel Queue Scheduling: It has several separate queues. It class have its own scheduling algorithm.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 53

Operating System 2018

Round Robin algorithm can be used for interactive processes and FCFS(first come first serve) algorithm can be used for batch system.

Multilevel Feedback Queue Scheduling: This allows to move a process one queue to another queue. First queue has lowest time slice, when it completed and process has more burts time then process moves its lower queue which has more(double approximately) queue. Its last queue works as FCFS (first come first serve).

3.5.Interrupts An interrupt is a signal from a device attached to a computer or from a program within the computer that requires the operating system to stop and figure out what to do next. Almost all personal (or larger) computers today are interrupt-driven - that is, they start down the list of computer instructions in one program (perhaps an application such as a word processor) and keep running the instructions until either (A) they can't go any further or (B) an interrupt signal is sensed. After the interrupt signal is sensed, the computer either resumes running the current program or begins running another program.

Basically, a single computer can perform only one computer instruction at a time. But, because it can be interrupted, it can take turns in which programs or sets of instructions that it performs. This is known as multitasking. It allows the user to do a number of different things at the same time. The computer simply takes turns managing the programs that the user starts. Of course, the computer operates at speeds that make it seem as though all of the user's tasks are being performed at the same time. (The computer's operating system is good at using little pauses in operations and user think time to work on other programs.)

An operating system usually has some code that is called an interrupt handler. The interrupt handler prioritizes the interrupts and saves them in a queue if more than one is waiting to be handled. The operating system has another little program, sometimes called a scheduler, that figures out which program to give control to next.

In general, there are hardware interrupts and software interrupts. A hardware interrupt occurs, for example, when an I/O operation is completed such as reading some data into the computer from a tape drive. A software interrupt occurs when an application program terminates or requests certain services from the operating system. In a personal computer, a hardware interrupt request (IRQ) has a value that associates it with a particular device.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 54

Operating System 2018

3.6. Deadlock A deadlock is a situation in which two computer programs sharing the same resource are effectively preventing each other from accessing the resource, resulting in both programs ceasing to function.

The earliest computer operating systems ran only one program at a time. All of the resources of the system were available to this one program. Later, operating systems ran multiple programs at once, interleaving them. Programs were required to specify in advance what resources they needed so that they could avoid conflicts with other programs running at the same time. Eventually some operating systems offered dynamic allocation of resources. Programs could request further allocations of resources after they had begun running. This led to the problem of the deadlock. Here is the simplest example:

Program 1 requests resource A and receives it. Program 2 requests resource B and receives it. Program 1 requests resource B and is queued up, pending the release of B. Program 2 requests resource A and is queued up, pending the release of A. Now neither program can proceed until the other program releases a resource. The operating system cannot know what action to take. At this point the only alternative is to abort (stop) one of the programs.

Learning to deal with deadlocks had a major impact on the development of operating systems and the structure of databases. Data was structured and the order of requests was constrained in order to avoid creating deadlocks.

3.6.1. Seven Cases of Deadlock Case 1: Deadlocks on file requests Two programs (P1, P2) and two files (F1, F2) Deadlock sequence: •P1 has access to F1 and also requires F2 •P2 has access to F2 and also requires F1

Case 2: Deadlocks in databases Transaction A might hold a lock on some rows in the Accounts table and needs to update some rows in the Orders table to finish. Transaction B holds locks on those very rows in the Orders table but needs to update the rows in the Accounts table held by Transaction A. Transaction A cannot complete its transaction because of the lock on Orders. Transaction B cannot complete its transaction because of the lock on Accounts. All activity comes to a halt and remains at a standstill forever unless the DBMS detects the deadlock and aborts one of the transactions.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 55

Operating System 2018

Case 3: Deadlocks in dedicated device allocation Two programs (P1, P2) •Need two tape drives each •Only two tape drives in system Deadlock sequence •P1 requests tape drive 1 and gets it •P2 requests tape drive 2 and gets it •P1 requests tape drive 2 but blocked •P2 requests tape drive 1 but blocked

Case 4: Deadlocks in multiple device allocation Three programs (P1, P2, P3) Three dedicated devices (tape drive, printer, plotter) Deadlock sequence •P1 requests and gets tape drive •P2 requests and gets printer •P3 requests and gets the plotter •P1 requests printer but blocked •P2 requests plotter but blocked •P3 requests tape drive but blocked

Case 5: Deadlocks in spooling Printer needs all job output before printing begins •Spooling system fills disk space area •No one job has entire print output in spool area •Results in partially completed output for all jobs

Case 6: Deadlocks in disk sharing

Two processes –Each process waiting for I/O request •One at cylinder 20 and one at cylinder 310 –Deadlock sequence •Neither I/O request satisfied •Device puts request on hold while attempting to fulfill other request for each request

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 56

Operating System 2018

Case 7: Deadlocks in a network –Seven computers on network •Each on different node –Direction of arrows •Indicates message flow –Deadlock sequence •All available buffer space fills

3.6.2. Conditions for Deadlock Deadlocks can be avoided by avoiding at least one of the four conditions, because all this four conditions are required simultaneously to cause deadlock. 1. Mutual Exclusion Resources shared such as read-only files do not lead to deadlocks but resources, such as printers and tape drives, requires exclusive access by a single process. 2. Hold and Wait In this condition processes must be prevented from holding one or more resources while simultaneously waiting for one or more others. 3. No Preemption Preemption of process resource allocations can avoid the condition of deadlocks, where ever possible. 4. Circular Wait Circular wait can be avoided if we number all resources, and require that processes request resources only in strictly increasing(or decreasing) order.

3.6.3. Modeling Deadlock A computer scientist/programmer named Holt showed how the four conditions for deadlock (as described in the previous tutorial) can be modelled using directed graphs. These graphs shown below.

In the above resource allocation graphs, the figure A, B, and C represents:

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 57

Operating System 2018

Figure Represents

(A) Holding a resource

(B) Requesting a resource

(C) Deadlock According to Hold, these graphs have the following two types of nodes:  Processes - shown in graph as circles  Resources - shown in graph as squares Here, in this graph, an arc from a square (resource node) to a circle (process node) means that the resource has previously been requested by, granted to, and is currently held by that process. As you can see from the figure given above, resource R is currently assigned to process A in figure A. An arc from a process to a resource means that the process is currently blocked waiting for that resource. As you can see from the above figure, in the figure B, process B is waiting for resource S. And, in the figure C, we see a deadlock, that is, the process C is waiting for the resource T, which is currently held by the process D. Here, process D is not about the release the resource T because it is waiting for resource U, held by C. Here both processes will wait forever.

3.6.4. Strategies for Handling Deadlocks 1. Deadlock Handling Strategy Prepared by : Sharma Hemant [email protected] 2. In a computer system deadlocks arise when members of a group of processes which hold resources are blocked indefinitely from access to resources held by other processes within the group.The Deadlock Problem 3. Circular wait :- There is a cycle in the wait-for graph. No preemption :- A resource cannot be preempted.  Hold and wait :- There must exist a process that is holding at least one resource and is waiting to acquire additional resources that are currently being held by other processes.  Mutual exclusion :- No resource can be shared by more than one process at a time. Conditions for Deadlock 4. There are three strategies for handling deadlocks. They are as below: 1. Deadlock Prevention 2. Deadlock Avoidance 3. Deadlock DetectionDeadlock Handling Strategy 5. Disadvantages:- Resources cannot be requested in the orders that are needed. Resources will be longer than necessary. First Method :- Prevent the circular-wait by defining a linear ordering of resource type. A process can be assigned resources only according to the linear ordering. Deadlock Prevention 6. Disadvantage:- 1. Inefficient use of resources. 2. Reduced concurrency. 3. Process can become deadlocked during the initial resource acquisition. 4. Future needs of a process cannot be always predicted. Second Method :- Prevent the hold-and-wait condition by

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 58

Operating System 2018

requiring the process to acquire all needed resources before starting execution. Deadlock Prevention 7. There are two methods to prevent deadlock in time-stamps. 1. Wait-die method 2. Wound- wait method Ex.:- Use time-stamps for transactions to a database. Each transaction has the time-stamps of its creation.  Third Method :- Use of time-stamps. Deadlock Prevention 8. The algorithm is: if [ e(t2) Wait-die method :- If a younger process is using the resource, then the older process waits. If an older process is holding the resource, the younger process kills itself. Deadlock Prevention < e(t1) ] halt_t2 (―wait‖); else halt_t1 (―die‖); 9. The algorithm is: if [ e(t2) Wound-wait method :- An alternative method by which resource request cycle may be avoided is to have an old process preempt the younger process that holds a resource. If a younger process wants a resource that an older one is using, then it waits until the old process is done. Deadlock Prevention < e(t1) ] halt_t1 (―wound‖); else halt_t2 (―wait‖); 10. Because of the following drawbacks, deadlocks avoidance can be impractical in distributed system. Dynamically grants a resource to a process if the resulting state is safe. A state is safe if there is at least one execution sequence that allows all processes to run to completion. Deadlock Avoidance 11. Disadvantage:- 1. Every site has to maintain global state of system. 2. Different sites may determine that state is safe, but global state may be unsafe : Verification for safe global state by different sites must be mutually exclusive. 3. Large overhead to check for every aDeadlock Avoidance llocation. 12. Detection:- 1. The algorithm must detect all existing deadlock in finite time. 2. The algorithm should not report non-existent deadlock. Requirements for the deadlock detection and resolution algorithms :  Principle :- Detection of a cycle in wait-for-graph proceeds concurrently with normal operation. Deadlock Detection 13. Observation :- Deadlock detection is the most popular strategy for handling deadlock in distributed system. Resolution (recovery) :- All existing wait-for dependencies in wait-for- graph must be removed, i.e. rollback one or more processes that are deadlocked and give their resources to other blocked processes. Deadlock Detection

3.6.5. Starvation In computer science, starvation is a problem encountered in concurrent computing where a process is perpetually denied necessary resources to process its work. Starvation may be caused by errors in a scheduling or mutual exclusion algorithm, but can also be caused by resource leaks, and can be intentionally caused via a denial-of-service attack such as a fork bomb.

The impossibility of starvation in a concurrent algorithm is called starvation- freedom, lockout-freedom or finite bypass,[3] is an instance of liveness, and is one of the two requirements for any mutual exclusion algorithm (the other being correctness). The name "finite bypass" means that any process (concurrent part) of the algorithm is bypassed at most a finite number times before being allowed access to the shared resource.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 59

Operating System 2018

Content: Deadlock Vs Starvation 1. Comparison Chart 2. Definition 3. Key Differences 4. Conclusion Comparison Chart BASIS FOR DEADLOCK STARVATION COMPARSION

Basic Deadlock is where no process proceeds, Starvation is where low priority processes get and get blocked. blocked, and high priority process proceeds.

Arising condition The occurrence of Mutual exclusion, Hold Enforcement of priorities, uncontrolled and wait, No preemption and Circular wait resource management. simultaneously.

Other name Circular wait. Lifelock.

Resources In deadlocked, requested resources are In starvation, the requested resources are blocked by the other processes. continuously used by high priority processes.

Prevention Avoiding mutual exclusion, hold and wait, and circular wait and allowing preemption.

3.7. Parallel Processing In computers, parallel processing is the processing of program instructions by dividing them among multiple processors with the objective of running a program in less time. In the earliest computers, only one program ran at a time. A computation-intensive program that took one hour to run and a tape copying program that took one hour to run would take a total of two hours to run. An early form of parallel processing allowed the interleaved execution of both programs together. The computer would start an I/O operation, and while it was waiting for the operation to complete, it would execute the processor- intensive program. The total execution time for the two jobs would be a little over one hour.

The simultaneous use of more than one CPU to execute a program. Ideally, parallel processing makes a program run faster because there are more engines (CPUs) running it. In practice, it is often difficult to divide a program in such a way that separate CPUs can execute different portions without interfering with each other. Most computers have just one CPU, but some models have several. There are even computers with thousands of CPUs. With single-CPU computers, it is possible to perform parallel processing by connecting the computers in a network. However, this type of parallel processing requires very sophisticated software called distributed processing software.

3.7.1. Evolution of Multiprocessors Multiprocessor Operating System refers to the use of two or more central processing units (CPU) within a single computer system. These multiple CPUs are in a close

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 60

Operating System 2018

communication sharing the computer bus, memory and other peripheral devices. These systems are referred as tightly coupled systems.

These types of systems are used when very high speed is required to process a large volume of data. These systems are generally used in environment like satellite control, weather forecasting etc. The basic organization of multiprocessing system is shown in fig.

Multiprocessing system is based on the symmetric multiprocessing model, in which each processor runs an identical copy of operating system and these copies communicate with each other. In this system processor is assigned a specific task. A master processor controls the system. This scheme defines a master-slave relationship. These systems can save money in compare to single processor systems because the processors can share peripherals, power supplies and other devices. The main advantage of multiprocessor system is to get more work done in a shorter period of time. Moreover, multiprocessor systems prove more reliable in the situations of failure of one processor. In this situation, the system with multiprocessor will not halt the system; it will only slow it down.

In order to employ multiprocessing operating system effectively, the computer system must have the followings: 1. Motherboard Support: A motherboard capable of handling multiple processors. This means additional sockets or slots for the extra chips and a chipset capable of handling the multiprocessing arrangement. 2. Processor Support: processors those are capable of being used in a multiprocessing system.

Multiprocessor system supports the processes to run in parallel. Parallel processing is the ability of the CPU to simultaneously process incoming jobs. This becomes most important in computer system, as the CPU divides and conquers the jobs. Generally the parallel processing is used in the fields like artificial intelligence and expert system, image processing, weather forecasting etc.

In a multiprocessor system, the dynamically sharing of resources among the various processors may cause therefore, a potential bottleneck. There are three main sources of contention that can be found in a multiprocessor operating system:

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 61

Operating System 2018

Locking system: In order to provide safe access to the resources shared among multiple processors, they need to be protected by locking scheme. The purpose of a locking is to serialize accesses to the protected resource by multiple processors. Undisciplined use of locking can severely degrade the performance of system. This form of contention can be reduced by using locking scheme, avoiding long critical sections, replacing locks with lock- free algorithms, or, whenever possible, avoiding sharing altogether.

Shared data: The continuous accesses to the shared data items by multiple processors (with one or more of them with data write) are serialized by the cache coherence protocol. Even in a moderate-scale system, serialization delays can have significant impact on the system performance. In addition, bursts of cache coherence traffic saturate the memory bus or the interconnection network, which also slows down the entire system. This form of contention can be eliminated by either avoiding sharing or, when this is not possible, by using replication techniques to reduce the rate of write accesses to the shared data.

False sharing: This form of contention arises when unrelated data items used by different processors are located next to each other in the memory and, therefore, share a single cache line: The effect of false sharing is the same as that of regular sharing bouncing of the cache line among several processors. Fortunately, once it is identified, false sharing can be easily eliminated by setting the memory layout of non-shared data.

Apart from eliminating bottlenecks in the system, a multiprocessor operating system developer should provide support for efficiently running user applications on the multiprocessor. Some of the aspects of such support include mechanisms for task placement and migration across processors, physical memory placement insuring most of the memory pages used by an application is located in the local memory, and scalable multiprocessor synchronization primitives.

3.8. Multi-Core Processors A multi-core processor is an integrated circuit (IC) to which two or more processors have been attached for enhanced performance, reduced power consumption, and more efficient simultaneous processing of multiple tasks (see parallel processing). A dual core set- up is somewhat comparable to having multiple, separate processors installed in the same computer, but because the two processors are actually plugged into the same socket, the connection between them is faster.

Ideally, a dual core processor is nearly twice as powerful as a single core processor. In practice, performance gains are said to be about fifty percent: a dual core processor is likely to be about one-and-a-half times as powerful as a single core processor.

Multi-core processing is a growing industry trend as single-core processors rapidly reach the physical limits of possible complexity and speed. Most current systems are multi-

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 62

Operating System 2018

core. Systems with a large number of processor core -- tens or hundreds -- are sometimes referred to as many-core or massively multi-core systems.

3.9. Typical Multiprocessing Configurations Types of MPs Various categories of multiprocessing systems can be identified. They include  Shared nothing (pure cluster)  Shared disks  Shared memory cluster (SMC)  Shared memory In shared nothing MP systems, each processor is a complete standalone machine, running its own copy of the OS. The processors do not share memory, caches, or disks, but are interconnected loosely, through a LAN. Although such systems enjoy the advantages of good scalability and high availability, they have the disadvantage of using an uncommon message- passing programming model.

Shared disk MP system processors also have their own memory and cache, but they do run in parallel and can share disks. They are loosely coupled through a LAN, with each one running a copy of the OS. Again, communication between processors is done through message passing. The advantages of shared disks are that disk data is addressable and coherent, whereas high availability is more easily obtained than with shared-memory systems. The disadvantage is that only limited scalability is possible, due to physical and logical access bottlenecks to shared data.

In a shared memory cluster (SMC), all processors have their own memory, disks, and I/O resources, while each processor runs a copy of the OS. However, the processors are tightly coupled through a switch, and communications between the processors are accomplished through the shared memory.

In a strictly shared memory arrangement, all of the processors are tightly coupled through a high-speed bus (or switch) on the same motherboard. They share the same global memory, disks, and I/O devices. Because the OS is designed to exploit this architecture, only one copy runs across all of the processors, making this a multithreaded memory configuration.

Importance of SMP The explosion of bandwidth for networking servers has placed unreasonable demands on single-processor systems, which cannot handle the workload! It must be distributed across multiple processors, using SMP. The main differences between an SMP system and every other system are that it utilizes more than one processor, and operates from a somewhat specialized motherboard. The main advantages to using SMP have to do with network speed and expense. Surprisingly, not only is an SMP solution faster than a single-processor solution, but also less expensive. Its higher performance is due to the fact that a

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 63

Operating System 2018

multiprocessor motherboard can deliver multiple paths of data processing, whereas a single- processor motherboard can only harness the single processor‘s capabilities. Compare it to moving 20 students to a server networking class using either a turbo-charged Ferrari or four Volkswagen Beetles. Even though the Beetles are cheaper, they will also get the job done faster. Of course, driving to class in a Ferrari would be more fun!

Hardware performance can be improved easily and inexpensively by placing more than one processor on the motherboard. One approach is called asymmetrical multiprocessing (ASMP), where specific jobs are assigned to specific processors. Doing ASMP effectively requires specialized knowledge about the tasks the computer should do, which is unavailable in a general-purpose operating system such as Linux.

The second approach is the one mentioned often in this book, called symmetrical multiprocessing (SMP), where all of the processors run in parallel, doing the same job. SMP is a specific implementation of multiprocessing whereby multiple CPUs share the same board, memory, peripherals, resources, and operating system (OS), physically connected via a common high-speed bus.

Compared to ASMP, SMP is relatively easy to implement because a single copy of the operating system is in charge of all the processors.

In early SMP environments, programmers had to remain aware that because the processors shared the same resources, including memory, it was possible for program code running in one CPU to affect the memory being used by another. Programming for these types of situations required special protection. Often, process programming was normally only run on one processor at a time, keeping the process safe from intrusion. However, the program kernel was still subject to call by various codes running on different processors. One solution involved running the kernel in spinlock mode, where only one CPU at a time was serviced. Other processors seeking entry had to wait until the first CPU was finished. Although the system was protected from competing processors, it operated inefficiently.

SMP systems do not usually exceed 16 processors, although newer machines released by Unix vendors support up to 64. Modern SMP software permits several CPUs to access the kernel simultaneously. Threaded processes can run on several CPUs at once, yet without suffering from kernel intrusion. Recall that a thread is a section of programming that has been time-sliced by the NOS in order to run simultaneously with other threads being executed in an SMP operation.

3.10. Process Synchronization Software Process Synchronization means sharing system resources by processes in a such a way that, Concurrent access to shared data is handled thereby minimizing the chance of inconsistent data. Maintaining data consistency demands mechanisms to ensure synchronized execution of cooperating processes.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 64

Operating System 2018

Process Synchronization was introduced to handle problems that arose while multiple process executions. Some of the problems are discussed below.

Critical Section Problem A Critical Section is a code segment that accesses shared variables and has to be executed as an atomic action. It means that in a group of cooperating processes, at a given point of time, only one process must be executing its critical section. If any other process also wants to execute its critical section, it must wait until the first one finishes.

Solution to Critical Section Problem A solution to the critical section problem must satisfy the following three conditions: 1. Mutual Exclusion Out of a group of cooperating processes, only one process can be in its critical section at a given point of time. 2. Progress If no process is in its critical section, and if one or more threads want to execute their critical section then any one of these threads must be allowed to get into its critical section.

3. Bounded Waiting After a process makes a request for getting into its critical section, there is a limit for how many other processes can get into their critical section, before this process's request is granted. So after the limit is reached, system must grant the process permission to get into its critical section.

Synchronization Hardware Many systems provide hardware support for critical section code. The critical section problem could be solved easily in a single-processor environment if we could disallow interrupts to occur while a shared variable or resource is being modified. In this manner, we could be sure that the current sequence of instructions would be allowed to execute in order without pre-emption. Unfortunately, this solution is not feasible in a multiprocessor environment.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 65

Operating System 2018

Disabling interrupt on a multiprocessor environment can be time consuming as the message is passed to all the processors.

This message transmission lag, delays entry of threads into critical section and the system efficiency decreases.

Mutex Locks As the synchronization hardware solution is not easy to implement for everyone, a strict software approach called Mutex Locks was introduced. In this approach, in the entry section of code, a LOCK is acquired over the critical resources modified and used inside critical section, and in the exit section that LOCK is released. As the resource is locked while a process executes its critical section hence no other process can access it.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 66

Operating System 2018

Unit – IV Device Management

4. Introduction Device Management What is Device Management? The Device Manager is a Control Panel applet in Microsoft Windows operating systems. It allows users to view and control the hardware attached to the computer. When a piece of hardware is not working, the offending hardware is highlighted for the user to deal with. The list of hardware can be sorted by various criteria.

For each device, users can:  Supply device drivers for the hardware  Enable or disable devices  Tell Windows to ignore malfunctioning devices  View other technical properties

Device Manager was introduced with Windows 95 and later added to Windows 2000. In NT- based versions, it is included as a Microsoft Management Console snap-in.

What is Device Manager Used For? Device Manager is used to manage the hardware devices installed in a computer like hard disk drives, keyboards, sound cards, USB devices, and more. Device Manager can be used for changing hardware configuration options, managing drivers, disabling and enabling hardware, identifying conflicts between hardware devices, and much more.

Think of Device Manager as the master list of hardware that Windows understands. All the hardware on your computer can be configured from this centralized utility.

How to Access Device Manager: Device Manager can be accessed several different ways including from the Control Panel, the Command Prompt, and more:

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 67

Operating System 2018

How to Use Device Manager: Each device listing in Device Manager contains detailed driver, system resource, and other configuration information and settings. When you change a setting for a piece of hardware, it changes the way Windows works with that hardware.

Here are some common things that you can do in Device Manager:  Update Drivers  Reinstall Drivers  View a Device's Status  Roll Back a Driver  Enable a Device  Disable a Device  Find a Driver's Version Number

Device Manager Availability: Device Manager is available in nearly every Microsoft Windows version including Windows 7, Windows Vista, Windows XP, Windows 2000, Windows ME, Windows 98, Windows 95, and more.

4.1. Type of Devices Computer devices such as mice, printers, scanners and speakers are known as peripheral hardware. These peripherals are further split into two categories, input devices and output devices. The function of the peripheral determines to which category it belongs.

Input Devices The computer mouse and scanner fall under the input device category. As the name suggests, input devices are used to send information to the computer. A mouse is used to input the movements of a cursor, while a scanner is used to input physical media into digital format.

Output Devices Printers and speakers are examples of computer output devices. Printers output digital information such as text or image files to a physical medium such as paper. Speakers output the audio from digital files into audible sound waves.

General purpose This category contains general-purpose operating systems like Linux and Windows. In the nmap-service-probes file this class is indicated by a lack of a d// field. Bridge A bridge combines two or more subnetworks into one. With a bridge this happens at a lower level than with a router. This category also includes things like Ethernet-to-serial bridges.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 68

Operating System 2018

Broadband router Devices in this category connect a network to the Internet via cable, ADSL, fiber optics, etc. Some of these devices provide network address translation, a firewall, port forwarding, or other services. Firewall A firewall controls what traffic is allowed into or out of a network. Some also have additional capabilities. This category doesn't include general-purpose operating systems that happen to come with a firewall, but it does include OS distributions purpose-built to work only as a firewall. Game console A video game console like the Xbox or PlayStation.

Hub A hub joins network segments by re-broadcasting all traffic. Hubs are distinct from switches, which selectively transmit packets only to relevant destinations. Load balancer A device that distributes inbound traffic to multiple devices to ease the load on those devices. Media device This category includes all kinds of audiovisual equipment, including portable music players, home audio systems, TVs, and projectors. PBX A private branch exchange, or PBX, routes telephone calls within a private organization and connects them to the public telephone network or VoIP. PDA A handheld computer. Devices that are also telephones go in the "phone" category. Phone A network-capable telephone that is not a VoIP phone. Devices in this category are typically mobile phones. Power-device Miscellaneous power devices like uninterruptable power supplies and surge protectors. Printer Network-enabled printers, including printers with an embedded print server. Print server A print server connects a printer to a network. Printers that contain their own print server go in the "printer" category instead. Proxy server Any kind of proxy, including web proxies and other servers that cache data or understand high-level protocols. Remote management Devices that allow servers or other equipment to be monitored or managed remotely. Router Routers connect multiple networks. They are distinct from hubs and switches because they route packets between different networks as opposed to extending one network.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 69

Operating System 2018

Security-misc Any security device that doesn't fall into the ―firewall‖ category belongs in this category. This includes intrusion detection and prevention systems. Specialized The catch-all category. If a device doesn't fall into one of the other categories, it is specialized. Examples in this category are diverse and include such things as clocks, oscilloscopes, climate sensors, and more. Storage-misc Data storage devices like tape decks and network-attached storage appliances. Switch A device that extends a network by selectively re-broadcasting packets. Switches are distinct from hubs, which broadcast all packets. Telecom-misc Devices used by telephone systems that aren't PBXs, like voicemail and ISDN systems. Terminal A device with a keyboard and monitor with the primary purpose of communicating directly with a terminal server or mainframe. Terminal server A device providing terminal facilities to clients over a network. VoIP adapter A device that converts between voice over IP (VoIP) protocols and normal telephone traffic. Also may convert different VoIP protocols. VoIP phone A phone capable of a VoIP protocol. WAP Wireless access points offer a wireless connection to a network. Most work with radio technology like 802.11b but some use infra-red or something else. Devices that could also be put in another category, like wireless broadband routers, are put in the WAP category because WAPs require special network considerations. Webcam Any kind of camera that stores or transmits pictures or video. This includes everything from consumer webcams to security system cameras.

4.2. Sequential Access Storage Media In computing, sequential access memory (SAM) is a class of data storage devices that read stored data in a sequence. This is in contrast to random access memory (RAM) where data can be accessed in any order. Sequential access devices are usually a form of or .

While sequential access memory is read in sequence, arbitrary locations can still be accessed by "seeking" to the requested location. This operation, however, is often relatively inefficient (see seek time, rotational latency).

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 70

Operating System 2018

Magnetic sequential access memory is typically used for secondary storage in general-purpose computers due to their higher density at lower cost compared to RAM, as well as resistance to wear and non-volatility. Magnetic tape is the only type of sequential access memory still in use; historically, has also been used.

In computing, Sequential Access Memory (SAM) is a class of data storage devices that read their data in sequence. This is in contrast to random access memory (RAM) where data can be accessed in any order. Sequential access devices are usually a form of magnetic memory.

While sequential access memory is read in sequence, accesses can still be made to arbitrary locations by "seeking" to the requested location. This operation, however, is often relatively inefficient (see seek time, rotational latency).

Magnetic sequential access memory is typically used for secondary storage in general-purpose computers due to their higher density at lower cost compared to RAM, as well as resistance to wear and non-volatility. Examples of SAM devices still in use include hard disks, CD-ROMs and magnetic tapes. Historically, drum memory has also been used.

Sequential Access in Programming Some programming languages and operating systems distinguish between sequential- access data files and random-access data files, allowing you to choose between the two types. Sequential-access files are faster if you always access records in the same order. Random- access files are faster if you need to read or write records in a random order.

Other Sequential Classifications Devices can also be classified as sequential access or random access. For example, a tape drive is a sequential-access device because to get to point q on the tape, the drive needs to pass through points a through p. A disk drive, on the other hand, is a random-access device because the drive can access any point on the disk without passing through all intervening points

4.3. DASD (direct access storage device) DASD, pronounced DAZ-dee (Direct access storage device), is a general term for magnetic disk storage devices. The term has historically been used in the mainframe and minicomputer (mid-range computer) environments and is sometimes used to refer to hard disk drives for personal computers. A redundant array of independent disks (RAID) is also a type of DASD.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 71

Operating System 2018

The "direct access" means that all data can be accessed directly in about the same amount of time rather than having to progress sequentially through the data.

A direct-access storage device (DASD) is another name for secondary storage devices that store data in discrete locations with a unique address, such as hard disk drives, optical drives and most magnetic storage devices. It is a technology and term coined for storage devices that IBM developed for use with mainframe computers and some microcomputers. These developed into the modern hard disk and its variants like the optical disk, which today we would simply call secondary storage.

Direct-access storage devices allow the host computer to access data directly from wherever it is stored within the storage device because each data chunk is saved in a discrete and separate location from other chunks, complete with a unique address. This allows the computer to directly point to that location to get the data. Access methods include indexed, sequential and direct (incorrectly referred as random access).

Even if the exact location of the data is known, the speed of access is largely dependent on the capability of the storage device; for example, even if the exact data location within a tape drive is known, the only access method is sequential access because of the inherent design of the tape, which means it must go through all of the locations preceding the one that is needed. Additionally, the tape cannot run very fast. This is in contrast to a direct access disk, which can quickly spin the disk and move the read/write head to the correct track and sector in fractions of a second.

Modern DASDs are internal and external hard disk drives that connect directly to the host computer via an IDE, SATA, eSATA, USB or FireWire interface. Unlike network-attached storage (NAS), DASDs become inaccessible once the device they are connected to goes offline.

A good example would be an internal or external disk drive that connects through an interface such as USB or FireWire.

4.4. Magnetic Disk Drive Access Times One or more disks are mounted on a spindle. The disks are sometimes called "platters". The spindle is connected to shaft of a drive motor. The drive motor rotates continuously at a constant speed (measured in RPM‘s). The disk material is non- magnetizeable (using aluminum and/or glass), but the disk surfaces are coated with a very thin magnetizable coating.

Read/write recording head (one or more) for each disk. The R/W heads are attached to an "access arm". The access arms are attached to a "boom". The boom is connected to a "step"

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 72

Operating System 2018

motor (also called a "servo-motor"). The step motor moves the boom and R/W heads to a track position and stops there before a read or write operation can occur.

On a hard drive, the read/write heads float on a cushion of air over the surfaces of the disks. The smaller the air gap, the closer the read/write head is to surface, the smaller the magnetized spot. So, the smaller the air gap is made, the more dense the recording of bits will be. Contaminants on the surface are larger than the air gap: air gap .00003 (30 millionths of an inch) human hair .003 (3 thousandths of an inch) paper .003 smoke particle .0015 dust particle .0003 finger prints .0006 If a contaminant "crashes" into the R/W head, then as with a car going over a large bump, the R/W head is forced up and then the access arm will slam it down onto the recording surface and gouge the magnetizable material off the surface, called a head crash. This makes the disk unusable. This was a significant problem when disk surfaces were exposed to the ambient air which is filled with particulates.

Hence, newer drives have the disks, spindle, R/W heads, access arms and boom enclosed in a sealed case that will not allow contamination from the outside environment. This technology was developed by IBM and was known as Winchester disk technology in the past, but the term has since been dropped since all hard disk drives now are constructed this way. There are 3 delay times involved in accessing and transferring data between the computer and the disk drive.  Seek time delay.  Rotational time delay.  Transfer time delay. It is **VERY** important to note that all these calculations are omitting the time necessary for the CPU to transmit data along the system bus to/from the disk drive controller.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 73

Operating System 2018

Seek Time The seek time for a disk operation is the time required to move the read/write head from the current track position to the target track position. What causes the delay?

- The R/W head is stopped over the current track. - The step motor must move the stopped R/W head across the surface to the target track - The R/W head must become stationary over the target track Characteristic seek time is determined by the "head movement profile" described by the graph. There are three time components in this movement profile: 1. start up time - the time for the R/W head to start moving from rest until it is traveling at maximum linear speed 2. travel time at max speed - the time the head travels at maximum linear speed until it begins to slow down 3. stop down time - the time required to bring the R/W head from its max. speed to a stationary position over the target track For short track to track head moves, the drive never reaches max head movement speed. Just have some start-up time and stop-down time. Long track to track head moves are called "Full stroke seek". For example, movement from the outer track to the inner track, or vice versa. Startup and stop down times are a small percentage of the total full stroke seek Travel time mainly spent passing over other tracks at maximum head movement speed. Most manufacturers only give average read and write seek time. For example, WD Cavier 10.1GB is 9.5 ms. There is no way for the programmer to know how much seek time is required because the position of the R/W head is unknown before the disk operation. The seek time is Non- deterministic (cannot be determined absolutely). So we must measure seek time "statistically", that is, using statistical measures of the seek time value: - Minimum seek time, - Average seek time - the "expected" seek time, denoted E(seek) - Maximum seek time, Max(seek) Typical values: - Min seek is between 1 ms up to < 10 ms - Avg seek 10 ms to 20 ms - Max seek from < 20 ms to > 30 ms

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 74

Operating System 2018

Rotational Latency The rotational latency for a disk operation is the time required to rotate the disk to a position where the start of target data is under the read/write head. The rotational latency is based on rotation speed. Latency is non-deterministic (it cannot be determined absolutely for any given disk operation, in general), and so must be treated "statistically", that is, using statistical measures of the latency: - Max latency = time of a full revolution = sec / rev - Average latency = time of ½ revolution = ½ of max latency Disk rotation speed is measured in Revolutions Per Minute (RPMs). To determine rotational latency, we need to know the time for one rotation - in other words, minutes per rotation. Hence, latency is the inverse of speed. Time of revolution can be computed as the inverse of revolutions per time. So, time per revolution = 1 / ( rev / time ). For example, assume we have a 3600RPM drive, 1 Max Latency = ------rev / time

1 = ------3600rev / 60 secs

60 secs = ------3600 Rev

1 sec 1000ms 16.67ms = ------= ------= ------60 Rev 60 rev 1 rev

= 16.67ms per revolution So, the max latency = 16.67ms and the average latency = 8.33ms.

Transfer Time The transfer time for a disk operation is the time required to transfer the data from (or to) the disk surface to (or from) the computer once the start of the data is under the R/W head. Transfer time is based on: 1 - speed of rotation 2 - density of data on the track 3 - amount of data to be transferred The rotational speed of the drive and the track capacity, or track density, can be combined into a single value which is the transfer rate. Remembering that one track = 1 revolution, we

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 75

Operating System 2018

find ... Transfer Rate = track capacity / rotational speed and so, the time to transfer a set of data is Transfer Time = Transfer Rate * Amount to Transfer For example, the HP9154A: Rotation Speed = 3000RPM --> 20ms/rev Sector Size = 256 Bytes Track Capacity = 28 sectors --> 7KB / track

So, transfer rate = 7 KB / 20ms = .35 KB / ms = 3.5KB / sec Note that the manufacturer's transfer rate will vary because of the block headers briefly mentioned above.

Example Let's look at the manufacturer's spec sheet for the Seagate Barracuda 7200.10 Serial ATA, model number ST3750640AS. Capacity 750 GB Discs 4 Sectors per Track 63 Bytes per Sector 512 Speed 7200 RPM Avg Latency 4.16 ms Track-to-Track Seek Time <0.8 ms for read; <1.0 ms per write Average Seek, Read < 8.5 ms Average Seek, Write < 10.0 ms

4.5. Components of the I/O Subsystem PC most likely has an I/O panel to either help keep all the connectors in one spot. On the I/O panel, you add various expansion options to the PC, and the I/O panel also provides places to plug in some standard devices (use this figure as your guide for what‘s what):

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 76

Operating System 2018

 Keyboard: The keyboard plugs into this little hole.  Mouse: Generally the same size and shape as the keyboard connector, this hole has a mouse icon nearby to tip you off.  USB: Plug snazzy devices into these Certs-size Universal Serial Bus (USB) slots.  COM/Serial: PCs have at least one of these connectors.  Video/VGA: Your PC‘s monitor can plug into this hole. A second, digital monitor connector may be available for plugging in LCD monitors.  SPDIF In, SPDIF Out: These connectors are used for digital audio.  Headphones/speakers: Plug in your PC‘s external speakers or headphones, or hook up the PC to a sound system.  Line In: Plug in a traditional audio-producing device (stereo, phonograph, VCR, and so on) into the PC for capturing sound.  Surround left/right: Also for surround sound, this is the jack into which you plug the rear left and right speakers.  Center/subwoofer: For a surround sound audio system, you plug the center speaker or subwoofer, or both, into this jack.  Microphone: The computer‘s microphone plugs into this jack.  Modem: Connect your PC‘s dialup modem to the phone jack in the wall.

4.6. Communication among Devices A communication device is a hardware device capable of transmitting an analog or digital signal over the telephone, other communication wire, or wirelessly. The best example of a communication device is a computer Modem, which is capable of sending and receiving a signal to allow computers to talk to other computers over the telephone. Other examples of communication devices include a network interface card (NIC), Wi-Fi devices, and an access point.

Communication device examples Below is a full listing of all the different types of communications devices you may encounter when dealing with a computer.

 Bluetooth devices Bluetooth is a computing and telecommunications industry specification that describes how devices such as mobile phones, computers, or personal digital assistants can communicate with each other.

Bluetooth is an RF technology that operates at 2.4 GHz, has an effective range of 32- feet (10 meters) (this range can change depending on the power class), and has a transfer rate of 1 Mbpsand throughput of 721 Kbps.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 77

Operating System 2018

How is Bluetooth used? A good example of how Bluetooth could be used is the ability to connect a computer to a cell phone without any wires or special connectors. The picture is an example of a USBBluetooth adapter from SMC.

 Infrared devices Method of transferring data without the use of wires. A common example of an infrared (Ir) device is a TV remote. However, infrared is also used with computers and devices like a cordless keyboard or mouse. The picture is an example of the Nintendo Wii remote and an example of an infrared device.

 Modem (over phone line) A modem may refer to any of the following: A Modem or Broadband Modem is a hardware device that connects a computer or router to a broadband network. For example, a Cable Modem and DSL Modem are two examples of these types of Modems.

Short for MODulator/DEModulator, a Modem is a hardware device that allows a computer to send and receive information over telephone lines by converting digital data into an analog signal used on phone lines.

Modems are referred to as an asynchronous device, meaning that the device transmits data in an intermittent stream of small packets. Once received, the receiving system then takes the data in the packets and reassembles it into a form the computer can use. Stop Data Start Stop Data Start 1 bit 8 bits 1 bit 1 bit 8 bits 1 bit Packet Packet 10 bits 10 bits

The above chart represents how an asynchronous transmission would be transmitted over a phone line. In asynchronous communication, one byte (eight bits) is transferred within one packet, which is equivalent to one character. However, for the computer to receive this information, each packet must contain a Start and a Stop bit; therefore, the complete packet would be ten bits. In the above chart is a transmission of the word HI, which is equivalent to two bytes (16 bits).

Types of computer Modems Below are the four versions of a computer Modem found in computers. Onboard Modem - Modem built onto the computer motherboard. These Modems cannot be removed but can be disabled through a Jumper or CMOS Setup. Internal Modem - Modem that connects to a PCI slot inside a newer desktop computer or ISA slot on an older computer. The Internal Modem shown at the beginning of this document is an example of a PCI Modem.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 78

Operating System 2018

External Modem - Modem within a box that connects to the computer externally, usually the Serial Ports or USB port. The picture is an example of an external USRobotics Modem. Removable Modem - Modem used with older laptops PCMCIA slot and can be added or removed as needed.

 Network card (using Ethernet) Short for Network Interface Card, the NIC is also referred to as an Ethernet card and network adapter. It is an expansion card that enables a computer to connect to a network; such as a home network, or the Internet using an Ethernet cable with an RJ- 45 connector. Due to the popularity and low cost of the Ethernet standard, most new computers have a network interface build directly into the motherboard. The top image shows the SMC EZ Card 10/100 PCI network card, one of the more common examples. The bottom picture shows a PC Card, more specifically the SMC EZ Card 10/100 wireless network card; found in laptop computers that do not have onboard wireless capabilities.

 Smartphone A smartphone is a cell phone that allows you to do more than just make phone calls and send text messages. Smartphones can browse the Internet and run basic software programs like a computer. Smartphones use a touch screen to allow users to interact with them. There are thousands of smartphone apps (software programs), including games, personal-use, and business-use programs that can all run on the phone. The picture is an example of the Apple iPhone, one of the most popular smartphones available today.

Does a smartphone have an operating system? Yes. Similar to a desktop or laptop computer, a smartphone has an operating system on it, like Windows or macOS. The four most common are iOS (created by Apple), Android(created by Google), BlackBerry (created by Research In Motion), and Windows Phone(created by Microsoft).

When was the first smartphone released? The first unofficial smartphone was developed by IBM in 1992. It was a prototype device, with PDA-like features, including maps, news feeds, and stock quotes. The prototype resulted in an improved version being released to the market in 1994, called the Simon Personal Communicator. This device was the first official smartphone, with capabilities to send and receive e-mails, and included apps like an address book, calculator, calendar, and a notepad.

 Wi-Fi devices (using a Wi-Fi router) (examples shown below) Short for Wireless Fidelity, Wi-Fi utilizes one of the IEEE 802.11 wireless standards to achieve a wireless connection to a network. A home wireless network uses a wireless access point or router to broadcast a signal using WAP or WEP encryption to send and receive signals from wireless devices on the network. The picture shows a Wireless

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 79

Operating System 2018

access point with two antennas and an example of how most home users connect to the Internet using a wireless device. Wireless adapters If the desktop computer or laptop does not have wireless, it requires a wireless adapter to connect to the wireless network. Below are examples of the different Wi-Fi adapters that can be used with a computer to connect to a wireless network.

In the picture above, the first image is a Linksys desktop Wi-Fi card that connects to a PCI slot on the motherboard. Next, the SMC wireless PC Card is used with older laptopsthat do not have a wireless option. Finally, the far right image is of Cisco USB Wi-Fi adapter that can be used on any computer with a USB port to connect to a Wireless network.

Why is Wi-Fi used? Without Wi-Fi, every network device would need to connect to the network with a network cable (typically Cat5). Having a cable for every computer and network device makes installation and deployment much more difficult, especially for a home without the proper wiring. It also makes mobility (e.g., moving around the home or office) impossible. With Wi- Fi, any compatible device with the proper reception and access rights can connect to the network without having to drag a cable to that device.

4.7.Management of I/O Requests

Definition - What does I/O Request mean? I/O request packets are kernel mode structures used for communication between the Windows Drive Model and Windows NT device drivers as well as with the Windows operating system. All the data details are passed on to the data structure via the single pointer, instead of following the old convention of transporting many small data arguments. These I/O requests are made to pass through many different processing stages. These stages are determined by the nature of the request, whether it is meant for the target device for a single- layered driver or a multilayered drive.

I/O request packets are basically used for communications between the device drivers and the operating system. It allows a particular process to get unblocked and be completely executed.

In the first step, a process is initiated that issues a blocking read on the file descriptor of a previously used file. The code of the operating system or the kernel has a system-call code that works towards checking the accuracy of the parameters. If the buffer cache already has the data, then the data is returned and the request is completed. In the situation that the data is not found in the buffer cache, a physical I/O is performed. This ensures that the process is removed from the run queue and placed in the wait queue. Thereafter, the device driver receives the request through the I/O subsystem. It is up to the device driver then to make space for the incoming data and schedule I/O. The device controller then works on the device hardware to carry out the process of data transfer. The DMA controller manages and operates the transfer of data to the kernel memory. When the transfer is finished, this creates

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 80

Operating System 2018

an interrupt which is received by an interrupt handler through the interrupt-vector table. It scans the data for important information and then returns the interrupt. This signal is then received by the device driver, which completes the request and also determines the status of the request. Lastly, it is up to the kernel to remove the process from the wait queue into the ready queue and the data is transferred to the address space. This step unblocks the process. So now, when the process is assigned to the CPU, it resumes work and is completed.

4.7.1. Operating system design issues Two objects are paramount in designing the I/O management facility: generality and efficiency.

4.7.1.1. Generality We always desire to manage all the I/O devices in a uniform manner, however the above differences make it difficult to achieve this goal, both from the point of view of the operating system and from the point of view of user processes. What we can do is to use a hierarchical approach to the design of the I/O function, which is similar to the abstraction scheme in object orientation theory. That is the routines that are involved in dealing with accessing I/O devices are divided into several layers, and each layer provides a concise interface for the immediate upper-level layer, so that most of the details of the I/O devices are hidden in lower-level layers and the user processes may operate the devices in terms of general functions, such as read, write, open, close, lock, unlock. What kind of hierarchy should be used depends on the type of I/O devices of concern.

Figure shows the organization of three different types of I/O devices.

A model of I/O organization

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 81

Operating System 2018

Figure (a) depicts the simplest case, a local peripheral device, which may be accessed in terms of a stream of bytes or records. The layers involved are as follows: • Logical I/O deals with the I/O device as a logical resource without concerning the details of actually controlling the device. This layer provides a simple interface for user processes: specifying a unique ID to this device and simple control commands, such as open, close, read, write, etc..

• Device I/O converts the requested operation from the logical I/O layer into a series of I/O instructions. Data may be buffered in this layer and forwarded in the format that is acceptable to the destination layer. • Scheduling and control: actually interacts with the I/O device, including queuing and scheduling of I/O operations, handling interrupts, collecting and reporting status information, etc.

For a communication device, rather than logical I/O, a communication protocol layer is used instead as Figure 1 (b) shows.

For a storage device on which a file system is used, more complexity is involved. Besides scheduling and control layer and device I/O layer, the following layers are also used: • Directory management provides user processes a hierarchical view of the collection of files stored on the device. Operations may be performed to add, or delete a directory. • File system provides a flat view of a collection of files. At this layer, a directory file is treated in the same way as other regular files, although the content of this special file includes information about files under this directory. The upper level may use this interface of this layer to open, close, read, write, add, or delete a file. Access control may also be included here. • Physical organization converts the logical references to files into physical addresses in terms of track, sector. Allocation and deallocation of storage space are also treated in this layer.

4.7.1.2. Efficiency Efficiency is the other objective in I/O subsystem design. Remember, at the beginning of this course, we have discussed three popular ways to access I/O devices:

• Programmed I/O means the microprocessor is involved all the way through the I/O process. The microprocessor issues command to initiate the I/O device, tell it what to do, and wait until the I/O process is finished. Almost all I/O devices are slower than the microprocessor, so the latter has to be idle for a long time, which results in inefficiency. • Interrupt-driven I/O otherwise aims to let the microprocessor and the I/O devices work simultaneously. With this scheme, the microprocessor, after issuing a command on behalf of a process to start an I/O operation, may turn to execute another process. When the I/O operation completes, an I/O interrupt will be generated to signal the microprocessor to resume the former process. Although switching between different processes involves overhead, it is still worth doing unless the context switching is too frequent. • DMA When a large amount of data needs to be transferred to/from an I/O device, it is not realistic any longer to take the interrupt-driven approach because frequent context switching is unavoidable in this case. To deal with this problem, the DMA approach is taken, in which a DMA controller is responsible to control the data exchange between main memory and an I/O device. What the microprocessor needs to do is simply to send necessary information to the

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 82

Operating System 2018

DMA controller at the very beginning. An interrupt is also generated finally so that the microprocessor knows the completion of the whole DMA process.

By considering whether the processor is directly involved in the I/O process and whether interrupt schemes are used or not, we may have Table 1, showing the similarity and difference among the above three schemes:

Table I/O techniques

From the above discussion, we can see the efficiency of the whole system is increased step by step more or less.

4.7.2. I/O buffering Let‘s begin with an example to introduce the necessity of I/O buffering. Suppose a user process wishes to read a block of data from a tape into a data area in the address space of this process at virtual location 1000. The most straightforward way to do so in the process is to execute an I/O command to the tape device and then wait for the data to be available.

However there are two problems with this approach. First, the process has to wait a long time before the completion of the operation due to the low speed of the tape device. Second, this data exchange may interfere with the swapping mechanism in the operation system. That is, before the whole operation is finished, the data area in the process to contain data from the tape has to remain in the main memory. Thus this section of space must be locked in some way so that it will not be swapped out to secondary memory.

To avoid the above inefficiency and inconvenience, it is possible to perform data input transfers in advance of requests being made or output transfers after the request is made, which is known as buffering. This section will discuss some of buffering schemes to improve the performance of the system.

Figure I/O Buffering Scheme

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 83

Operating System 2018

4.7.2.1. Single buffer The simplest buffering scheme is single buffering. As illustrated in Figure (b), when a user process issues an I/O request, the operating system allocates a buffer in the system portion of main memory to the operation.

With this scheme, data is first gradually transferred into the system buffer. When the transfer is complete, the data is then moved into the user process space. Note that this is not the end of the story. The I/O facility in the operating system continues to read more data from the device, which is called reading ahead. This is performed because user processes usually access data on an I/O device sequentially. Thus this approach will generally speedup the I/O operations requested by a process. After a block of data becomes available and is delivered to the user process, the operation system may read ahead another block of data while the process is processing the former block. This approach also makes it possible to swap out the process that made I/O requests.

To support this mechanism, more effort needs to be made in the operating system, such as tracking the buffers allocated to user processes. What‘s more, the swapping of the process though is made possible, another problem arises. That is if the I/O request has been made and the process is to be swapped out to the same secondary storage device as involved in the I/O request, then the swapping will not happen until after the I/O request is finished.

Nevertheless, at this moment, it may not be appropriate any more to swap out the process, since the data it has been waiting for are available and it may proceed to process them. Despite these disadvantages, it is still worth using the buffering scheme. A similar circumstance will occur regarding outbound data transfer. When data are to be outputted to a device, they may be copied from the requesting process into a system buffer first. Then the process may simply continue or be swapped out.

4.7.2.2. Double buffer An improvement of single buffering is to use two system buffers for a user process, called double buffering, as Figure (c) shows. In this case, moving data from one system buffer to the process and reading data from the I/O device to the other buffer may be performed simultaneously. Again, this improvement comes at the cost of increased complexity.

4.7.2.3. Circular buffer The idea of double buffering may be generalized to circular buffering. That is more than two buffers are used and the collection of these buffers is referred to as a circular buffer, as illus- trated in Figure (d). In this way, although the I/O device is much slower, there may be enough data in the system buffers for the process to read.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 84

Operating System 2018

Unit – V File Management 5. Introduction of File Management Definition - What does File Management System mean? A file management system is a type of software that manages data files in a computer system. It has limited capabilities and is designed to manage individual or group files, such as special office documents and records. It may display report details, like owner, creation date, state of completion and similar features useful in an office environment.

A file management system is also known as a file manager.

A file management system should not be confused with a file system, which manages all types of data and files in an operating system (OS), or a database management system (DBMS), which has relational database capabilities and includes a programming language for further data manipulation.

A file management system's tracking component is key to the creation and management of this system, where documents containing various stages of processing are shared and interchanged on an ongoing basis.

The system may contain features like:  Assigning queued document numbers for processing  Owner and process mapping to track various stages of processing  Report generation  Notes  Status  Create, modify, copy, delete and other file operations

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 85

Operating System 2018

5.1. Interacting with the File Manager File System What is file? The system that an operating system or program uses to organize and keep track of files. For example, a hierarchical file system is one that uses directories to organize files into a tree structure.

Although the operating system provides its own file management system, you can buy separate file management systems. These systems interact smoothly with the operating system but provide more features, such as improved backup procedures and stricter file protection.

Files are used for storing the Information of the user; But Files are organized into the System by using a Specific Manner. Generally for arranging all the Files, directories or Folders are used.

A Folder is also called as the Container of the Files in which many Sub directors and Files are Stored. But there is also a Access Method in which data of the File will be accessed by the user.

Means from which Location Information of the File will be Accessible. There are various types of Storage Architectures which specify fro which Locations. File will be Read and from which Locations Data will read and how the data will be Read from the Files.

There are three types of Attributes of the Files 1) Read We can only read the data but we can‘t modify the Data of the File. 2) Write We can also write the data and also Read the data 3) Hidden File will not be shown to the user. But these will Remain Saved on the user Computer.

Types of File Systems: 1. Disk File Systems: It is a file system designed for the storage of files on a data storage device, most commonly a disk drive, which might be directly or indirectly connected to the computer. Example: FAT, FAT32, NTFS, HFS,etc. 2. Flash File Systems: It is a file system designed for storing files on flash memory devices. Example: JFFS2, YAFFS. 3. Database File Systems: It is a new concept of file management in which Instead of hierarchical structured management, files are identified by their characteristics, like type of file, topic, author or similar metadata.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 86

Operating System 2018

4. Transactional File Systems: This a special kind of file system in that it logs events or transactions to files. Each operation that you do may involve changes to a number of different files and disk structures. It is important that they all be executed at the same time. For example, file system used in bank‘s that sends money to other bank electronically. This type of file system are synchronized and are fault tolerant and having a high degree of overhead. 5. Network File System: This type of file system acts as a client for a remote file access protocol, providing access to files on a server. Example: NFS, FTP, etc. 6. Special Purpose File System: This type of file system includes systems where the files are arranged dynamically by software. These are most commonly used by file-centric OS‘s such as UNIX.

5.2. File Organisation File organization refers to the way data is stored in a file. File organization is very important because it determines the methods of access, efficiency, flexibility and storage devices to use. There are four methods of organizing files on a storage media. This include:  sequential,  random,  serial and  indexed-sequential

1. Sequential file organization  Records are stored and accessed in a particular order sorted using a key field.  Retrieval requires searching sequentially through the entire file record by record to the end.  Because the record in a file are sorted in a particular order, better file searching methods like the binary search technique can be used to reduce the time used for searching a file .  Since the records are sorted, it is possible to know in which half of the file a particular record being searched is located, Hence this method repeatedly divides the set of records in the file into two halves and searches only the half on which the records is found.  For example, of the file has records with key fields 20, 30, 40, 50, 60 and the computer is searching for a record with key field 50, it starts at 40 upwards in its search, ignoring the first half of the set.

Advantages of sequential file organization  The sorting makes it easy to access records.  The binary chop technique can be used to reduce record search time by as much as half the time taken.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 87

Operating System 2018

Disadvantages of sequential file organization  The sorting does not remove the need to access other records as the search looks for particular records.  Sequential records cannot support modern technologies that require fast access to stored records.  The requirement that all records be of the same size is sometimes difficult to enforce.

2. Random or direct file organization  Records are stored randomly but accessed directly.  To access a file stored randomly, a record key is used to determine where a record is stored on the storage media.  Magnetic and optical disks allow data to be stored and accessed randomly.

Advantages of random file access  Quick retrieval of records.  The records can be of different sizes.

3. Serial file organization  Records in a file are stored and accessed one after another.  The records are not stored in any way on the storage medium this type of organization is mainly used on magnetic tapes.

Advantages of serial file organization  It is simple  It is cheap

Disadvantages of serial file organization  It is cumbersome to access because you have to access all proceeding records before retrieving the one being searched.  Wastage of space on medium in form of inter-record gap.  It cannot support modern high speed requirements for quick record access.

Indexed-sequential file organization method  Almost similar to sequential method only that, an index is used to enable the computer to locate individual records on the storage media. For example, on a magnetic drum, records are stored sequential on the tracks. However, each record is assigned an index that can be used to access it directly.

5.3.Physical Storage Allocation The main idea behind allocation is effective utilization of file space and fast access of the files. There are three types of allocation: 1. contiguous allocation 2. linked allocation

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 88

Operating System 2018

3. indexed allocation

In addition to storing the actual file data on the disk drive, the file system also stores metadata about the files: the name of each file, when it was last edited, exactly where it is on the disk, and what parts of the disk are "free". Free areas are not currently in use by the file data or the metadata, and so available for storing new files. (The places where this metadata is stored are often called "inodes", "chunks", "file allocation tables", etc.)

To keep track of the free space, the file system maintains a free-space list which tracks all the disk blocks which are free. To create a file, the required space is reserved for the file and the corresponding space is removed from the free list linked to each other.

Contiguous allocation With contiguous allocation, each file occupies contiguous blocks on the disk. The location of a file is defined by the disk address of the first block and its length.

A file allocated disk space using contiguous allocation method Both sequential access and direct/Random access are supported by the contiguous allocation. As it support random access by using Disk Block Address we can jump directly on the required location.

In linked allocation In linked allocation, each file is a linked list of disk blocks. The directory contains a pointer to the first and optionally the last block of the file. For example, a file of 5 blocks which starts at block 4, might continue at block 7, then block 16, block 10, and finally block 27. Each block contains a pointer to the next block and the last block contains a NIL pointer. The value -1 may be used for NIL to differentiate it from block 0.

Example of a file which has been allocated disk space using linked allocation method.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 89

Operating System 2018

With linked allocation, each directory entry has a pointer to the first disk block of the file. This pointer is initialized to nil (the end-of-list pointer value) to signify an empty file. A write to a file removes the first free block and writes to that block. This new block is then linked to the end of the file. To read a file, the pointers are just followed from block to block.

There is no external fragmentation with linked allocation. Any free block can be used to satisfy a request. Notice that there is no need to declare the size of a file when that file is created either. A file can continue to grow as long as there are free blocks. Linked allocation, does have disadvantages, however. The major problem is that it is inefficient to support direct-access; it is effective only for sequential-access files. To find the block of a file, it must start at the beginning of that file and follow the pointers until the block is reached. Note that each access to a pointer requires a disk read.

Indexed allocation Linked allocation does not support random access of files, since each block can only be found from the previous. Indexed allocation solves this problem by bringing all the pointers together into an index block. One disk block is just used to store DBAs (disk block addresses) of a file.

a file allocated disk space using Indexed allocation Method

Every file is associated with its own index node. If a file is very large then one disk block may not be sufficient to hold all associated DBAs of that file. If a file is very small then some disk block space is wasted as DBAs are less and a single disk block could still hold more DBAs.

This method solves the problem of fragmentation as the blocks can be stored at any location.

5.4. Access Methods Definition - What does Access Method mean? An access method is a software component, operating system service or network interface that handles the storage/retrieval and sending/receipt of data. Access methods provide an application programming interface (API) for programmers to perform these services, which rely on low-level, specialized instructions.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 90

Operating System 2018

In the 1960s, access methods were introduced by IBM as part of the mainframe OS/360 to provide access to data stored on disks, magnetic tapes and other external storage devices. In non-mainframe operating systems, this function is handled by device drivers.

Access methods provide a convenient service to programmers for managing data storage and transmission. While providing the programmer with flexibility, the abstraction hides the many details regarding low-level disk access and communication protocol operations.

Access methods include internal structures to organize data as data sets, system-provided programs or macros to define data sets, and utility programs for data set processing. Error detection and correction capabilities are also provided.

Storage-oriented access methods include:  Basic direct access method (BDAM)  Basic sequential access method (BSAM)  Basic partitioned access method (BPAM)  Queued sequential access method (QSAM)  Indexed sequential access method (ISAM)  Virtual storage access method (VSAM)  Object access method (OAM)

Network-oriented access methods include:  Basic telecommunications access method (BTAM)  Queued teleprocessing access method (QTAM)  Telecommunications access method (TCAM)  Virtual telecommunications access method (VTAM)  Channeled access method (CAM)

The information stored in the file needs to be accessed and read into the computer memory. There are different methods available to do it. Some of them are:

 Sequential Access:

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 91

Operating System 2018

o This is the most common method. o Here the information present in the file is accessed in a sequential fashion, one record after the other. o It is a very common approach which is used by editors and compilers usually. o The Read and Write operations form the major part of the operations done on a file. o A read operation reads the next portion of the file and automatically advances the file pointer, which tracks the I/O location. o A write operation appends to the end of the file and advances to the end of the newly written material.

 Direct Access

o This type of access method provides a speedy access to the file. It provides immediate access to large amount of information. o Here a file is made up of logical records that allow programs to read and write. o It allows the programs to read and write the records in a rapid manner in no particular (or pre-defined) order. o It is based on the disk-model of a file, as a disk allows random access to any block. o For direct access, we can view the file as a numbered sequence of blocks or records. o This method is usually used in databases.

 Indexed access: o This method is built on top of Direct access method. o Here an index contains the pointers to various blocks of the file. o So, to find a record inside a file, we firstly search the index and later use the pointer obtained to access the file directly and find the record we have been searching for.

5.5. Levels File Management Systems Single Level Directory The simplest method is to have one big list of all the files on the disk. The entire system will contain only one directory which is supposed to mention all the files present in the file system. The directory contains one entry per each file present on the file system.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 92

Operating System 2018

This type of directories can be used for a simple system. Advantages 1. Implementation is very simple. 2. If the sizes of the files are very small then the searching becomes faster. 3. File creation, searching, deletion is very simple since we have only one directory. Disadvantages 1. We cannot have two files with the same name. 2. The directory may be very big therefore searching for a file may take so much time. 3. Protection cannot be implemented for multiple users. 4. There are no ways to group same kind of files. 5. Choosing the unique name for every file is a bit complex and limits the number of files in the system because most of the Operating System limits the number of characters used to construct the file name.

Two Level Directory In two level directory systems, we can create a separate directory for each user. There is one master directory which contains separate directories dedicated to each user. For each user, there is a different directory present at the second level, containing group of user's file. The system doesn't let a user to enter in the other user's directory without permission.

Characteristics of two level directory system 1. Each files has a path name as /User-name/directory-name/ 2. Different users can have the same file name. 3. Searching becomes more efficient as only one user's list needs to be traversed. 4. The same kind of files cannot be grouped into a single directory for a particular user. Every Operating System maintains a variable as PWD which contains the present directory name (present user name) so that the searching can be done appropriately.

5.6. Access Control Verification Module Access Control Principles The mechanism which defines user access is called access control. When the server receives a request, it uses the authentication information provided by the user in the bind operation

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 93

Operating System 2018

and the access control instructions (ACIs) defined in the server to allow or deny access to directory information. The server can allow or deny permissions for actions on entries like read, write, search, and compare. The permission level granted to a user may depend on the authentication information provided.

Access control in Directory Server is flexible enough to provide very precise rules on when the ACIs are applicable: o For the entire directory, a subtree of the directory, specific entries in the directory (including entries defining configuration tasks), or a specific set of entry attributes. o For a specific user, all users belonging to a specific group or role, or all users of the directory. o For a specific location such as an IP address or a DNS name.

ACI Structure Access control instructions are stored in the directory as attributes of entries. The aci attribute is an operational attribute; it is available for use on every entry in the directory, regardless of whether it is defined for the object class of the entry. It is used by the Directory Server to evaluate what rights are granted or denied when it receives an LDAP request from a client. The aci attribute is returned in an ldapsearch operation if specifically requested.

The three main parts of an ACI statement are: o Target o Permission o Bind Rule The permission and bind rule portions of the ACI are set as a pair, also called an access control rule (ACR). The specified permission is granted or denied depending on whether the accompanying rule is evaluated to be true.

ACI Placement If an entry containing an ACI does not have any child entries, the ACI applies to that entry only. If the entry has child entries, the ACI applies to the entry itself and all entries below it. As a direct consequence, when the server evaluates access permissions to any given entry, it verifies the ACIs for every entry between the one requested and the directory suffix, as well as the ACIs on the entry itself. The aci attribute is multi-valued, which means that you can define several ACIs for the same entry or subtree.

An ACI created on an entry can be set so it does not apply directly to that entry but to some or all of the entries in the subtree below it. The advantage of this is that general ACIs can be placed at a high level in the directory tree that effectively apply to entries more likely to be located lower in the tree. For example, an ACI that targets entries that include the inetorgperson object class can be created at the level of an organizationalUnit entry or a locality entry.

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 94

Operating System 2018

Minimize the number of ACIs in the directory tree by placing general rules at high level branch points. To limit the scope of more specific rules, place them as close as possible to leaf entries.

ACI Evaluation To evaluate the access rights to a particular entry, the server compiles a list of the ACIs present on the entry itself and on the parent entries back up to the top level entry stored on the Directory Server. ACIs are evaluated across all of the databases for a particular Directory Server but not across all Directory Server instances.

The evaluation of this list of ACIs is done based on the semantics of the ACIs, not on their placement in the directory tree. This means that ACIs that are close to the root of the directory tree do not take precedence over ACIs that are closer to the leaves of the directory tree.

For Directory Server ACIs, the precedence rule is that ACIs that deny access take precedence over ACIs that allow access. Between ACIs that allow access, union semantics apply, so there is no precedence.

For example, if you deny write permission at the directory's root level, then none of the users can write to the directory, regardless of the specific permissions you grant them. To grant a specific user write permissions to the directory, you have to restrict the scope of the original denial for write permission so that it does not include the user.

ACI Limitations When creating an access control policy for your directory service, you need to be aware of the following restrictions: o If your directory tree is distributed over several servers using the chaining feature, some restrictions apply to the keywords you can use in access control statements: o ACIs that depend on group entries (groupdn keyword) must be located on the same server as the group entry. If the group is dynamic, then all members of the group must have an entry on the server, too. If the group is static, the members' entries can be located on remote servers. o ACIs that depend on role definitions (roledn keyword) must be located on the same server as the role definition entry. Every entry that is intended to have the role must also be located on the same server.

However, you can match values stored in the target entry with values stored in the entry of the bind user; for example, using the userattr keyword. Access is evaluated normally even if the bind user does not have an entry on the server that holds the ACI.

********** All the Best **********

A.Tamilmani, MIT, MCA, PGDCA, MPhil, Asst.Prof in IT, BDUCCL Kumulur Page 95