2005-2011 Infosys Limited, Bangalore, India. All rights reserved. Infosys believes the information in this document is accurate as of its publication date; such information is subject to change without notice. Infosys acknowledges the proprietary rights of other companies to the trademarks, product names and such other intellectual property rights mentioned in this document. Except as expressly permitted, neither this document nor any part of it may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, printing, photocopying, recording or otherwise, without the prior permission of Infosys Limited and/or any named intellectual property rights holders under this document.
Education and Research Department Infosys Limited Electronics City Hosur Road Bangalore - 561 229, India.
1. V. Rajaraman: Fundamentals of Computers, 4 th Edition Published by PHI, 2007
2. Andrew S. Tanenbaum Structured Computer Organization, Fifth Edition, Prentice Hall of India, 2002
3. Ron White, How computers work, Millennium Edition, Techmedia, 2002 Infosys Technologies Limited Table of Contents
Version 1.0 iv Table of Contents
COPYRIGHT NOTICE ............................................................. ERROR! BOOKMARK NOT DEFINED. 1. INTRODUCTION ..................................................................................................... 1 2. MEMORY MANAGEMENT ........................................................................................... 3 2.1. SINGLE CONTIGUOUS MEMORY ALLOCATION ...................................................................... 3 2.2. FIXED PARTITION MEMORY ALLOCATION .......................................................................... 5 2.3. VARIABLE PARTITION MEMORY ALLOCATION ...................................................................... 6 2.4. RELOCATABLE PARTITION MEMORY ALLOCATION ................................................................. 7 2.5. SIMPLE PAGED ALLOCATION ...................................................................................... 9 2.6. INTRODUCTION TO VIRTUAL MEMORY CONCEPT ................................................................ 16 2.7. DEMAND PAGING ............................................................................................... 17 2.8. PAGE REPLACEMENT ALGORITHMS FOR DEMAND PAGING ....................................................... 19 2.9. SIMPLE SEGMENTATION ......................................................................................... 27 2.10. PAGED SEGMENTATION ......................................................................................... 30 3. PROCESS MANAGEMENT......................................................................................... 33 3.1. STRUCTURE OF A PROCESS ..................................................................................... 34 3.2. PROCESS STATES AND STATE TRANSITIONS ...................................................................... 36 3.3. MULTIPLE PROCESSES .......................................................................................... 41 3.4. INTER PROCESS COMMUNICATION ............................................................................... 41 3.5. MULTIPROGRAMMING, MULTIPROCESSING AND MULTITASKING .................................................. 43 3.6. TYPES OF MULTITASKING ....................................................................................... 45 3.7. THREADS ....................................................................................................... 47 3.8. SCHEDULING ................................................................................................... 50 3.8.1. Types of Scheduling ................................................................................. 52 3.8.2. Shortest Job First (SJF) Algorithm ............................................................... 54 3.8.3. Round Robin (RR) Algorithm ...................................................................... 57 3.8.4. Priority Scheduling .................................................................................. 58 3.8.5. Multi Level Queue Scheduling .................................................................... 61 3.9. PROCESS COORDINATION ....................................................................................... 63 3.9.1. Semaphores ........................................................................................... 64 3.9.2. Deadlocks ............................................................................................. 65 4. FILE SYSTEM MANAGEMENT .................................................................................... 68 4.1. MS-DOS FILE SYSTEM ......................................................................................... 68 4.2. FILE ORGANIZATION IN MS-DOS ............................................................................... 71 4.3. DATA ACCESS IN MS-DOS ...................................................................................... 73 4.4. VOLUME STRUCTURE OF THE DISK IN MS-DOS ................................................................. 76 4.5. MS-DOS BOOTING PROCESS ................................................................................... 77 4.6. UNIX FILE SYSTEM ............................................................................................. 78 4.7. FILE ORGANIZATION IN UNIX .................................................................................. 79 4.8. DATA ACCESS IN UNIX ......................................................................................... 80 4.9. VOLUME STRUCTURE OF THE DISK IN UNIX ..................................................................... 83 4.10. FILE PERMISSIONS .............................................................................................. 84 4.11. NEW TECHNOLOGY FILE SYSTEM (NTFS) ...................................................................... 85 4.12. FEATURES OF THE NTFS FILE SYSTEM .......................................................................... 86 4.13. OVERVIEW OF THE PARTITION STRUCTURE: ..................................................................... 86 4.14. LIMITATIONS OF NTFS ......................................................................................... 87 5. DEVICE MANAGEMENT ........................................................................................... 88 5.1. I/O CHANNELS, INTERRUPTS AND INTERRUPT HANDLING ....................................................... 88 Infosys Technologies Limited Table of Contents
Version 1.0 v 5.2. DIRECT MEMORY ACCESS ....................................................................................... 89 5.3. SOFTWARE INTERRUPTS ........................................................................................ 89 5.4. STRUCTURE OF AN I/O SYSTEM ................................................................................ 90 5.5. TYPES OF DEVICE ALLOCATION ................................................................................. 90 5.6. DISK SCHEDULING .............................................................................................. 92 6. SUMMARY .......................................................................................................... 94 7. EXERCISES ......................................................................................................... 95 GLOSSARY ................................................................................................................ 96 INDEX ...................................................................................................................... 99
Infosys Limited Operating Systems
Version 1.0 1 1. Introduction Operating System (OS) is a set of system programs which provides an environment to help the user to execute the programs. The OS is a resource manager (refer to Figure 1-1) which allocates and manages various resources like processor(s), main memory, input/output devices and information (files) on secondary memory devices. The purpose of studying OS concepts is to understand the capabilities and limitations of this resource manager. An understanding of the same helps in writing effective programs.
Figure 1-1: Operating System Services
Some examples of operating systems are MS-DOS, OS/2, Windows 3.x, Windows 95, Windows NT, Windows XP, MVS and UNIX.
Some of the major resources managed by the OS are mentioned in Table 1.
OS (Resource Manager) Hard Disk Manages Processor Utilization File Management Memory Management Device Management Processor Memory Printer Infosys Limited Operating Systems
Version 1.0 2
Major Resource Examples Manager Memory Primary memory
Memory management Processors CPU, I/O processors
Process management I/O devices Tapes, Printers, Terminals, mouse, Secondary Devices.
Device management Information 1 Files, data
File system management Table 1: Major Resources and Examples Recall that a program is a sequence of instructions telling the computer what to do. This program should be copied from the secondary memory to the main memory before executing the same. The OS, which is a set of programs, is also copied to main memory so as to manage the other resources.
1 Information: Data with context. Memory Infosys Limited Operating Systems
Version 1.0 3
2. Memory Management Memory management influences the performance of an operating system. Memory management deals with strategies for managing the memory so as to get an optimal performance from the OS. For a computer, the memory manager addresses the following questions:
x When should a program be brought into main memory? x Where does a program sit in the main memory? x What parameters should be considered while placing a program in a particular location in main memory? x What should be done if the main memory is completely occupied?
This section covers some of the fundamental concepts of various memory management schemes. The selection of a particular technique depends on various factors such as hardware support, memory available etc.
The functions of memory allocation and management are:
x allows as many user jobs 2 as possible to be present in memory x responds to changes in memory demand by individual user jobs x prevents unauthorized changes to a user jobs memory region x implements allocation and memory addressing as efficiently as possible
The question is how to achieve the above. For the rest of this material it is assumed that OS is residing in the upper portion of the memory. The following sub-sections will introduce the various memory management schemes along with their advantages and disadvantages. 2.1. Single Contiguous Memory Allocation In single contiguous allocation, the users job is assigned the complete control of the CPU until the job completes or an error occurs. During this time, the users job is the only program which would reside in memory apart from the operating system.
The various possibilities when single contiguous memory allocation technique is used are highlighted in Figure 2-1.
2 User Jobs: All programs, except the OS, which are loaded into main memory for execution. Infosys Limited Operating Systems
Version 1.0 4
Figure 2-1: Single Contiguous Allocation
The memory in Figure 2-1 is of 70K of size.
Case1: Denotes a scenario where in the users job occupies the complete available memory (the upper part of the memory is however, reserved for the OS program).
Case2: 30K of memory which is free but the new job cannot be put in memory because of the single contiguous allocation technique. From the above figure and the related discussion, the following advantages and disadvantages of single contiguous allocation technique can be seen.
Advantages:
It is simple to implement
Disadvantages:
It leads to wastage of memory which is called fragmentation This memory management technique would lead to uniprogramming 3 . Hence it cannot be used for multiprogramming 4
It leads to wastage of CPU time (wastage of time). When the current job in memory is waiting for an input or output operation the CPU is left idle
3 Uniprogramming: Ability of the OS to allow only one process to reside in memory. 4 Multiprogramming: The act of having multiple programs in memory ready for execution is called multiprogramming. OS Memory OS Users Job Unused Users Job Memory New Job Waiting for CPU time I am waiting / Case:1 Case:2 20K 50K 20K 20K 30K 20K Infosys Limited Operating Systems
Version 1.0 5 To overcome these disadvantages, the following memory management techniques are used. 2.2. Fixed Partition Memory Allocation In the fixed partitioned memory allocation, the memory is divided into various partitions each of fixed size. This would allow several user jobs to reside in the memory. Refer Figure 2-2 for the discussion on fixed partitioned memory allocation.
Figure 2-2: Fixed Partition Allocation
The memory is divided into various partitions of fixed size as shown in Figure 2-2. The OS occupies 20K of memory and there are four more partitions of size 10K, 10K, 20K and 10K respectively.
Case1: There are three jobs residing in memory each of which fits exactly into the respective partitions. One more partitioned memory is available for a user job. This type of fixed partition allocation supports multiprogramming.
Case2: Suppose that a new job of size 40K arrives for execution. It can be seen that the total amount of free memory is 40K but the new job cannot fit in to memory for execution because of lack of contiguous free space.
Case3: This depicts a scenario where job 4 is allocated a memory partition of 20K but it has occupied only 10K of this memory partition and the remaining 10K is unused.
Both case2 and case3 lead to a scenario where there is free memory available but the same cannot be used for a new job. This peculiar situation is called fragmentation of memory. OS (20K) Job 1 Memory Case:1 Job 2 Job 3 Free OS (20K) Free Memory Case:2 Job 2 Free Free OS (20K) Free Memory Case:3 Job 2 Not Used Free Job 4 (Only 10K used) 20K 10K 10K 20K 10K 20K 10K 10K 20K 10K 20K 10K 10K 20K 10K Infosys Limited Operating Systems
Version 1.0 6 Case2 leads to external fragmentation wherein there is enough free memory for a new job but they are not contiguous. Case3 leads to internal fragmentation wherein there is an unused part of memory internal to a memory partition.
To summarize: x Advantage of fixed partitioned allocation is to provide multiprogramming
x Disadvantages of fixed partitioned allocation are internal and external fragmentation of memory
x The issue of fragmentation can be resolved in many ways. Some of these are discussed in the subsequent sub-sections 2.3. Variable Partition Memory Allocation In this memory management technique there is no pre-determined (fixed) partitioning of memory. Instead this technique allocates the exact amount of memory required for a job. As a result of this jobs are put in memory in consecutive areas until the entire memory is full or till the remaining free space is too small to accommodate a new job. An example of variable partition allocation is shown in Figure 2-3.
Figure 2-3: Variable Partition Allocation
The advantage of variable partition allocation over fixed partition allocation is that it prevents internal fragmentation. The disadvantage of variable partition allocation is that it could still cause external fragmentation of memory. OS (20K) Job 1 (10K) Memory Case:1 Job 2 (10K) Job 3 (20K) Free (10K) OS (20K) Free (10K) Memory Case:2 Job 2 (10K) Free (20K) Job 4 (10K) New Job (30K) I am waiting for free memory / Infosys Limited Operating Systems
Version 1.0 7
Suppose that a job (Job 1) terminates, then the memory occupied by this job is released and such freed spaces in the memory are called holes. Even though the total free space may be sufficient to accommodate a new job, there may not be a single large enough hole to accommodate the new job. This is shown in case2 of Figure 2-3. Such holes when formed in between the currently executing jobs, will lead to external fragmentation of memory. Recall that the external fragmentation refers to the wastage of free memory spaces which occur outside the memory space allocated for a job that is currently being executed. If currently executing Job (Job 2 in case2 of Figure 2-3), which is in between the holes, terminates then the holes can be combined to form one big hole. This is called coalescence 5 of holes. 2.4. Relocatable Partition Memory Allocation The external fragmentation caused by variable partition memory allocation can be overcome by relocating the currently executing jobs so that the remaining holes can be combined into one large block of memory. This technique of relocating all occupied areas of memory to one end of the memory so as to get one large block of free memory space is called compaction. Figure 2-4 shows the result of new job allocated to the memory after compaction.
5 Coalescence: Merging. Infosys Limited Operating Systems
Version 1.0 8
Figure 2-4: Compaction
In this technique, the currently executing job (Job 2 in case2) is shifted to one end of the memory, thereby allowing the holes (free spaces) to be combined so that the total available free space is large enough to hold the new incoming job process (case3) which was not possible in the previous case.
The advantage of Relocatable Partition technique is that it is relatively simpler to implement in comparison to the other techniques which address the problem of external fragmentation.
Some of the disadvantages of Relocatable Partition technique are mentioned below:
1. Relocating the currently executing jobs afresh would lead to problems in executing instructions that are address dependent (absolute addressing). To address this problem one has to change all the absolute addresses. This problem doesnt occur in case of relative addressing mechanism.
OS (20K) Job 1 (10K) Memory Case:1 Job 2 (10K) Job 3 (20K) Free (10K) OS (20K) Free (10K) Memory Case:2 Job 2 (10K) Free (20K) Free (10K) Memory Case:3 I am waiting / New Job (40K) - New Job (40K) Job 1 is completed Job 3 is completed After Compaction Job 2 (10K) OS (20K) Infosys Limited Operating Systems
Version 1.0 9 2. Compaction will have the desired effect of making the total free space more usable for the incoming new jobs, but is achieved at the expense of large scale movement of the currently executing jobs. All the jobs need to be suspended while the re-shuffle takes place. Hence decision has to be made as to when and how often to perform the compaction.
The memory is compacted:
x As soon as any job terminates (Figure 2-4 depicts this scenario) x When a new job cannot be loaded into memory due to fragmentation (Figure 2-4 depicts this scenario) x At fixed time intervals 2.5. Simple Paged Allocation Another technique to overcome external fragmentation is called Simple Paging. To understand the concept of simple paging, it is necessary to understand the importance of logical and physical address space.
Memory is divided into bytes or words. Each location in memory has an address and the set of addresses available for a program is called its address space. The address space of a program is similar to my locker space in a locker room (refer to Figure 2-5).
Infosys Limited Operating Systems
Version 1.0 10
Figure 2-5: Address Space
The address space perceived by the programmer is normally called the logical address space. The logical address space is one contiguous series of memory addresses. When the program executes the logical address space is mapped to the physical address space in memory by the OS. The physical address space need not be contiguous. Figure 2-6 illustrates the mapping from logical address and physical address space.
Locker Room My locker space Memory My locker My Program (Address Space) 8 12 16 20 Infosys Limited Operating Systems
Version 1.0 11
Figure 2-6: Logical Address vs. Physical Address
Simple paging is a memory management technique which allows the physical address space of a job to be non-contiguous. The fundamental idea of simple paging is mentioned below.
x The jobs address space is divided into number of fixed size memory blocks, of the same size, called pages (typically 4K in size)
x The main memory address space is also divided into blocks or frames of the same size (4K size)
x The loading of the job into memory involves transferring these pages into some memory frames My Program My Program (Address Space) My Program (Address Space) Logical Address Space 8K 4K 4K Physical Address Space L o g i c a l t o P h y s i c a l A d d r e s s c o n v e r s i o n Infosys Limited Operating Systems
Version 1.0 12
Figure 2-7: Simple Paged Allocation Consider two jobs namely Job A and Job B as shown in Figure 2-7.
Job As address space is divided into 3 pages, each of 4k size and Job Bs address space is divided into 2 pages, each of 4k size. When these jobs are loaded into memory the pages are transferred to frames (of 4K size) in memory. Note that whenever a new job needs to be loaded in the memory, it is split up into different pages and accommodated into frames distributed in the memory space. If contiguous frames are not available, then the new incoming job's pages are accommodated into the available frames, even if they are not contiguous.
Page 0 Page 1 Page 2 Job A Memory Space Frame 1 Frame 2 Frame 3 Free Frame Frame 4 Frame 5 Free Frame Frame 6 Frame 7 Free Frame Frame 8 Page 0 Page 1 Job B A - 0 A - 1 A - 2 B - 0 B - 1 Frame 0 Infosys Limited Operating Systems
Version 1.0 13 As mentioned earlier the OS (specifically the memory manager) translates the logical address (pages) to the physical address (frames) by using a page table (refer to Figure 2-8 for the discussion on page table and address translation).
Figure 2-8: Page table and address translation
An address in jobs address space is considered to be of the form (p,d) where p is the page number containing the memory location and d is the displacement (offset) of the memory location from the start of the page. This page number acts as index to a page table which is created for every job. This page table gives the corresponding frame number in the main memory for the particular page. This frame number added with the displacement would give the physical address.
The Page table has two purposes:
1. It has got entries which map each page number in the program (in the secondary memory) and the corresponding page frame number (or block number present in the primary memory).
2 24 p d 1 24 p d 3 6 1 0 1 2 Page Table 1048 1024 + Memory Infosys Limited Operating Systems
Version 1.0 14 2. Since there is one to one mapping between the page number and the frame number, even if the pages are not contiguous in the primary memory, there exists a link between all the pages of a job through this mapping in the page table.
The address calculation using Page Table: The objective is to find out the physical location of the page in the primary memory so that it can be accessed. The page table gives a mapping between the frame number and the page number. This means for any given page, one can get the frame number (or block number) from the page table. Now the binary representation of this block number marks the beginning or the starting address of the 4K page in the primary memory as indicated below. If the physical frame 1 is located at an address of 1024 in the physical memory, then the 2 nd frame will be at 5120 if the frame (page) size is equal to 4K.
Page - Number Block - Number 2 (Binary Equivalent 0010)
1 (Binary Equivalent 0001) Table 2: Page Table
Each page (4K) is divided into partitions of fixed size each. The number of bits required to address the displacement depends on the size of the page (frame). In the example mentioned in Figure 2-8, the size of the page is assumed to be 4K. Hence the total number of bits to locate any location within the page will be 12 (since 2 12 =4096=4K). Also since there are 3 pages used by the job, the number of bits required to represent the page numbers are 2 (2 2 =4, which is the nearest power of 2 for representing 3 pages). Hence the logical address of the accessed location will be 10 000000011000 .
Now the next step is to locate the physical address.
Since a page resembles a block (page frame), the displacement of the required partition, from the beginning of the page is the same as the displacement of the partition from the beginning of a frame. So, this displacement, put together with the beginning of the frame gives the exact physical location of the information in the memory. Since page 2 is located at frame 1 in the memory whose address is 1024, the physical address of the accessed location will be 1024+24=1048 as shown in Figure 2-8.
Infosys Limited Operating Systems
Version 1.0 15 Example: For a particular implementation of simple paged allocation, the page size is fixed to 4K and the total size of the program is 16 Kilobytes6. What is the total number of pages that are required for this program? Also calculate the number of bits in the logical address.
Answer: The total number of pages required is 4 (= 16K/4K) The total number of bits in logical address= 2+ 12 (2bits for addressing 4 pages and 12 bits for representing the displacement within the page)
Advantages:
Since each page is separately allocated, the users job need not be contiguous. However, locations within a page must be contiguous. Paging solves the problem of fragmentation to a large extent.
Note that, there is an overhead of address translation involved with every memory reference.
Disadvantages:
Considerable amount of hardware support is needed. Some part of memory is used up for storing page tables also. The most undesirable part of this scheme is that the simple paged allocation requires all pages of the entire job to be in the memory. Hence the total number of jobs in the memory is limited by the size of the physical memory. In other words the total size of all the jobs in the memory obviously cannot be more than the physical memory size.
Simple paged allocation would also lead to internal fragmentation. Consider a case where a job requires 17K of memory (refer to Figure 2-9) and when simple paged allocation, with a page size of 4K is used, the jobs address space would be divided into 5 pages and subsequently to 5 frames. In the last frame only 1K would be used and the remaining 3K would be wasted leading to internal fragmentation.
6 KiloByte: It is a unit of measure for data storage. 1 Kilobyte(KB) = 1024 bytes. Infosys Limited Operating Systems
Version 1.0 16
Figure 2-9: Internal Fragmentation due to simple Paging Allocation
The drawbacks of simple paged allocation are overcome in the subsequent memory management schemes. 2.6. Introduction to Virtual Memory Concept The simple paged memory allocation technique highlighted the fact that the job need not occupy contiguous locations and also that the address translation from logical to physical address space can happen at run time. These facts raise some interesting questions.
Is it possible to have only a part of the job in memory and still execute the job? If yes, then what implications does it have with respect to the maximum size of a job in comparison with the actual physical memory available?
The answer to the first question is yes and the implication which it has on the maximum size of a job in comparison with the actual physical memory is that the job size is not bound by the physical memory limit.
Virtual 7 Memory is an imaginary memory area that is supported by some operating systems with the aid of the hardware devices. The ability of the OS to allow only part of the job to reside in the memory during execution ensures that the size of physical memory does not impose any restrictions on the size of the job. This gives every job in memory a feel that they have infinite memory available for them, though the fact is that the size of the secondary memory limits the size of a job. The actual physical memory onto which the job gets loaded is
7 Virtual: Something that is not real Frame 1 Frame 2 Frame 3 A - 2 Frame 0 Job A 17K Page 0 Page 1 Page 2 Page 3 Page 4 3K of memory wasted Frame 4 Only 1K used A - 0 A - 1 A - 3 A - 4 Logical Address Memory Pages of Job A Infosys Limited Operating Systems
Version 1.0 17 called the Real Memory. To understand this concept, consider the following real world example (refer to Figure 2-10).
Figure 2-10: Buffet Example
Whenever a person goes for a buffet dinner, he/she feels that there is an infinite amount of food that he/she could consume. The size of the plate does not impose a restriction on the total amount of food that he/she could consume. As and when required the person loads the plate with the desired amount of food and consumes it. In reality the total amount of food available in the buffet table would limit the total amount of food the person can consume. 2.7. Demand Paging Demand paging is a memory management technique wherein the pages of a job are loaded into memory only on demand. This means that not all pages are loaded into memory simultaneously for the execution of the job.
The demand paging technique works on the virtual memory concept. The physical memory corresponds to the size of the plate and infinite memory, which the user perceives, corresponds to the buffet. Unlike simple paging, in demand paging technique the pages are loaded into memory as and when required (on demand). Note that the demand paging technique also divides the jobs address space into pages and these pages are loaded into frames in memory (refer to Figure 2-11).
Size of plate not a restriction to the amount of food consumed Infinite Amount of food that could be consumed Infosys Limited Operating Systems
Version 1.0 18
Figure 2-11: Demand Paging
In the above figure page 0 and page 1 of job A are not in physical memory. They are moved into physical memory based on the demand. The process of moving pages in and out of physical memory is called swapping.
The address translation in the demand paging technique is done in a similar way as in the case of simple paging. The page table is used to find out the page number to frame number mapping. Each page table entry in the case of demand paging has a number of additional fields 8 of which two are of prime importance. They are called the status field and the modified field.
The status field is used to indicate whether the page is in memory or in the secondary storage. Initially all page table entries have the status field as not available (0) which means that all the pages are currently in secondary memory and are not available in main memory. Now as and when the page is loaded to the main memory the status field for that page is changed to available (1) in the corresponding page table entry. The next time when the same page is required in memory this status field value (1) would tell the OS that the page is already in the main memory. Also when this page is moved (swapped) out of memory the status field is set to not available (0).
The modified field is used to indicate whether a page has been modified when it is present in physical memory. Recall that the process of moving pages in and out of physical memory is called Swapping. Whenever the physical memory is full, Swapping involves two steps. First some pages need to be swapped out and then the new page has to be swapped in to the physical memory. If the modified field is not set for a particular page then this page need not be swapped out to the secondary memory, instead the OS directly overwrites the new page in this frame. This is similar to the real world example of closing a word document. If no changes are made to the word document after it was opened then closing the document
8 Additional fields: The Additional fields are also called control bits as they store some control information in a 1 bit field. Job A Memory Space Page 0 Page 1 Job B B - 0 B - 1 Page 0 Page 1 Page 2 A - 2 Frame 1 Frame 2 Frame 0 Infosys Limited Operating Systems
Version 1.0 19 would not save anything to the disk. Suppose that some changes have been made to the word document and when the document is closed then a dialog box pops up asking whether the document should be saved. This is because of the modified field being set. A modified field when set would have a value of 1 else would have a value of 0.
Demand paging technique could lead to a scenario where in a job might try to access a particular page which is not available in main memory. This would lead to a fault called page fault. Consider the example mentioned in Figure 2-11. Suppose that the page 2 of job A, which is currently in memory, tries to access the page 1 of job A then a page fault would occur because page 1 is not loaded in memory. Once this page fault is caused the OS would replace one of the existing pages in physical memory with page 1 of job A. The process of removing some pages from physical memory to accommodate new pages is called Page Replacement. Now the question is what should be the criteria to replace pages from physical memory.
There are various page replacement algorithms 9 which could be used. Some of these page replacement algorithms are discussed below. The principle behind these page replacement algorithms are discussed with the aid of real world examples. 2.8. Page Replacement Algorithms for Demand Paging
Least Frequently Used (LFU): Consider a soccer game where the coach needs to replace one of the eleven players with a substitute. The playing eleven resembles the physical memory which is completely occupied and the substitute resembles the new page that needs to be swapped in to the physical memory.
In the LFU algorithm a counter is maintained which keeps track of the number of times a player strikes the ball. The player with the least number of strikes would be replaced by the substitute. Similarly when the LFU algorithm is used for page replacement, the page in memory which was used the least number of times (a reference counter is maintained in the page table entry) would be swapped out so as to swap in the new page.
Refer to Figure 2-12 for the discussion on LFU algorithm. The memory is completely occupied with one page from job A and two pages from job B. Now when a new page needs to be loaded into memory, page 2 of job A would be swapped out of memory as it has the least reference count which implies that it was the least frequently used page among all three pages in the memory. Note that the value X in the page table entries in Figure 2-12 refer to a dont care value.
9 Algorithm: A sequence of instructions to perform a particular task. It is does not have any syntax and is written as English statements. Infosys Limited Operating Systems
Version 1.0 20
Figure 2-12: LFU Algorithm
Least recently used (LRU): Consider a volleyball match where the coach needs to replace one of the playing 6 with a substitute. This scenario is similar to the case where in the physical memory is fully occupied with pages and there is a new page which needs to be swapped in to the physical memory.
In the LRU algorithm a time stamping 10 is maintained which keeps track of the last time when a player stroked the ball. The player whose time stamping is the earliest would be replaced by the substitute. Similarly when LRU algorithm is used for the page replacement a time stamping, which keep tracks of the last time when the page was referenced, is maintained for every page. The page which has the earliest time stamping (i.e. the page whose time since the last reference is greatest) would be replaced.
10 Time stamping: Recording the date and time of access (or creation / existence) of information. LFU Algorithm Player 05 is replaced because of the least number of strikes Job A Memory Space Job B Page 0 Page 1 Page 2 Frame 1 Frame 2 Frame 0 X X 0 0 0 1 X X 1 X X 2 Frame Number StatusModified Reference Counter page to frame mapping Page 0 Page 1 1 2 1 1 0 1 5 3 Frame Number StatusModified Reference Counter page to frame mapping Page table for Job A Page table for Job B Infosys Limited Operating Systems
Version 1.0 21
Figure 2-13: LRU Algorithm
Refer to Figure 2-13 for the discussion on the LRU algorithm. Page 2 of job A which has the earliest time stamping (09:45 Hrs) would be swapped out from the physical memory so that the new page could be swapped in. Please note that each page table entry has quite a lot of control bits of which only the entries which are relevant to the example are shown.
Not Recently Used (NRU): There is a considerable overhead 11 involved in maintaining the time stamping in LRU algorithm. Say for example there might be one page in physical memory which was referenced last at 09:45 Hrs yesterday and another page which was referenced last at 09:40 Hrs today. Clearly the first page has an older time stamping. The overhead involved here is that the day of last reference of a page also needs to be maintained.
11 Overhead: operating expense. LRU Algorithm 2 Game Starts Player 2 is replaced because the last time she touched the ball is much earlier than the others Job A Job B Frame 1 Frame 2 Frame 0 Memory Space Page 0 Page 1 Page 2 X X 0 0 0 1 X X 1 X X 09:45 Frame Number StatusModified Time Stamping page to frame mapping Page 0 Page 1 1 2 1 1 0 1 09:48 09:58 Frame Number StatusModified Time Stamping page to frame mapping Page table for Job A Page table for Job B Infosys Limited Operating Systems
Version 1.0 22 Instead of this overhead, the Not Recently Used algorithm uses a page reference bit which is reset to 0 at regular time intervals. When the page is referenced again the page reference bit is set to 1 to indicate that the page was referenced during the current interval. Now the page replacement is done by identifying the page which has this bit as 0. If there are multiple such pages then one of the pages would be swapped out based on some more additional parameters. These parameters vary based on the OS and can include the reference counter, etc.
Consider the following real world example. A cricket team is touring a particular country and is playing six one day international matches. If a player does not score a single run in the three consecutive one day matches (the time interval is three consecutive matches) then that player is dropped and another reserve player is bought in for the next match. This technique is precisely the not recently used technique and the time interval is three consecutive matches.
Refer to Figure 2-14 for the discussion on the NRU algorithm. Page 2 of job A which has its reference bit as 0 would be swapped out from the physical memory so that the new page could be swapped in. Please note that the time interval is decided and maintained by the OS.
Infosys Limited Operating Systems
Version 1.0 23
Figure 2-14: NRU Algorithm
First In First Out (FIFO): In this algorithm the page which is in memory for the longest time would be swapped out of physical memory. In other words the page which was swapped into memory first would be the first to be swapped out (as in a queue). The OS would maintain the information of which page came first into memory.
Job A Job B Frame 1 Frame 2 Frame 0 Memory Space Page 0 Page 1 Page 2 X X 0 0 0 1 X X 1 X X 0 Frame Number StatusModified Reference Bit page to frame mapping Page 0 Page 1 1 2 1 1 0 1 1 1 Frame Number StatusModified Reference Bit page to frame mapping This player is replaced as he was out for 0 in the last 3 matches Infosys Limited Operating Systems
Version 1.0 24
Figure 2-15: FIFO Algorithm Refer to Figure 2-15 for the discussion of FIFO algorithm. The sequence bit in the page table entry indicates the order in which the pages were loaded into physical memory. Page 2 of job A was the first page to be loaded followed by page 0 of job B and then page 1 of job B. Hence using the FIFO algorithm page 2 of job A would be swapped out from physical memory to swap in a new page into physical memory.
Other possible algorithms are Least Frequently Used (page which is used least number of times is the one to be replaced), Most Frequently Used, Most Recently Used etc.
In most of the operating systems however, a combination of the Page Replacement algorithms are implemented. For example in case of LFU, to decide the page to be replaced when there Job A Job B Frame 1 Frame 2 Frame 0 Memory Space Page 0 Page 1 Page 2 X X 0 0 0 1 X X 1 X X 1 Frame Number StatusModified Sequence Bit page to frame mapping Page 0 Page 1 1 2 1 1 0 1 2 3 Frame Number StatusModified Sequence Bit page to frame mapping The person who is first in the queue would be the first one out Page table for Job A Page table for Job B Infosys Limited Operating Systems
Version 1.0 25 is a tie between 2 or more pages due to same frequency of usage, we can use FIFO or LRU algorithm.
Advantages of Demand paging:
One of the main advantages of demand paging is the ability to have only a part of the job in physical memory while executing it.
Disadvantages: Demand Paging has few disadvantages as well.
Consider a job of 20K where the page size is fixed as 1K by the OS. Then the jobs address space would be divided into 20 pages and there is possibility of at least 20 page faults occurring before this job is executed. This is because initially when the OS picks up this job for execution none of its pages are in memory. Also the number of page faults will increase as the number of frames allotted in the physical memory decreases. In such scenarios the OS could end up spending most of its time swapping pages in and out of the memory. When such high paging activity happens frequently, it is referred to as Thrashing. When Thrashing occurs, the OS spends most of the time paging than executing the job. One sure sign of thrashing is when the program stops responding and disk drive light keeps blinking on and off. Like simple paging, demand paging could also lead to internal fragmentation.
Some of the possible solutions, implemented by a few OS, to avoid thrashing are mentioned below.
x Swapping out of inactive pages from the physical memory at regular intervals. In this way the OS ensures that there is a certain level of free frames available at any given time. x Pre-fetching the pages into memory there by reducing the number of page faults. x Stealing page frames from other jobs so as to accommodate a new page of the current job. This technique of stealing page frames is called page Stealing.
Examples on page replacement:
1. Consider a dynamic paging scheme, where the page numbers and request sequence is as follows: 3 1 3 4 2 4 1 2 3 1 2 4 2 3 1 3
Given that the main memory has 3 frames, calculate the number of page faults that would occur. Assume that initially none of the pages are in main memory and FIFO algorithm is used for page replacement.
Infosys Limited Operating Systems
Version 1.0 26 Solution: Since initially there are no pages in the memory, there will be page faults when page 3 is requested. The same will happen with page 1. But when page 3 is again required, since it is already in the main memory it need not be fetched (swapped in) from secondary memory. Hence no page fault. But when page 4 is required there will be a page fault again. Next in sequence is page 2 which is not in the main memory and hence will have to be fetched in. But since only 3 frames are available, one of these have to be replaced and the first one to have got swapped in would be the first one to be replaced. In this example page 3 will make way for page 2. rest of the process is depicted in the Error! Reference source not found.6.
Figure 2-16: FIFO -Example The number of page faults in the above case is 10.
2. If the above problem is solved using LRU technique then the solution will be as shown in Error! Reference source not found.7. Total page faults will be equal to 9.
Figure 2-17: LRU- Example
3. Similarly if LFU is used then the solution will be as shown in Figure 2-18. Note that when the page 2 is required to be brought into the memory, pages 1 and 4 are both with a frequency of one each. Under such condition one may have to consider FIFO or any other strategy to resolve the tie. In the example shown FIFO is used to break the tie.
Note: Frequency count of a page is reset to zero as soon as that page is swapped out of the memory. Another variation of this policy could be to maintain the frequency count even when the page is swapped out as shown in Figure 2-19.
Figure 2-19: LFU with LRU (counter not reset)
2.9. Simple Segmentation Simple Segmentation is a memory management technique where the jobs address space is divided into number of variable length memory blocks called Segments. A Segment is a grouping of information which is treated as one logical entity. The logical address space is a collection of these segments. The basic difference between simple paging and simple 3 3 4 2 3 4 1 3 1 3 4 2 4 1 2 3 1 2 4 2 3 1 3 3 4 1 3 1 3 4 2 3 4 1 3 4 2 3 4 1 Frames Pages required Frequency Count for pages 1,2,3 and 4 1 3 2 4 0 1 0 0 1 1 0 0 1 2 0 0 1 2 0 1 0 2 1 1 0 2 1 2 1 2 0 2 0 2 1 2 0 3 1 2 1 3 0 2 0 3 1 2 0 3 1 3 0 3 2 3 0 4 2 3 1 4 0 3 1 5 0 3 3 2 4 1 3 4 1 3 1 3 4 2 4 1 2 3 1 2 4 2 3 1 3 3 4 1 3 1 3 4 2 2 3 1 2 4 1 2 4 3 Frames Pages required Frequency Count for pages 1,2,3 and 4 1 3 2 4 0 1 0 0 1 1 0 0 1 2 0 0 1 2 0 1 1 2 1 1 1 2 1 2 2 2 1 2 2 2 2 2 2 3 2 2 3 3 2 2 3 3 3 2 3 3 3 3 3 3 4 3 3 4 4 3 4 4 4 3 4 5 4 3 2 1 3 Infosys Limited Operating Systems
Version 1.0 28 segmentation is that the page size in simple paging is fixed whereas in simple segmentation the size of segments can vary.
Figure 2-20: Simple Segmentation
Refer to Figure 2-20 for the discussion on simple segmentation. Job As address space is divided into three segments. Segment 0 is of size 2K, segment 1 is of size 8K and segment 2 is of size 4K. Similarly job Bs address space is divided into two segments, one of 6K size and the Memory Space OS A-2 B-0 A-1 Free A-0 Free B-1 Free Segment 0 Segment 1 Job B Job A Segment 0 Segment 1 Segment 2 2K 8K 4K 6K 2K Infosys Limited Operating Systems
Version 1.0 29 other of 2K size. Now when these jobs are loaded into physical memory the corresponding segments could be positioned independently in memory 12 . This helps in better utilization of free space areas.
In the simple segmentation technique the logical to physical address translation is done by the memory manager using a table called the segment table. This table has an entry for all segments of a job and it gives the address in the physical memory where in the particular segment has to be loaded. Refer to Figure 2-21 for the discussion on segment table and address translation.
Figure 2-21: Segment Table and Address Translation
In simple segmentation an address in jobs address space is considered to be of the form (s,d) where s is the segment number of the logical address space and d is the displacement (offset) of the memory location from the start of that segment. This segment number (segment number 2 in Figure 2-21) acts as an index to the segment table which is created for every job. This segment table gives the length of the segment and byte address (address of the starting location of the segment) for every segment that is created for a job. The address translation is done as follows. First the memory manager checks if the displacement is less than the length of the segment. If not an error is raised, else the displacement is added to the byte address to give the actual physical address of (s, d). Note that in simple segmentation
12 The segments need not be positioned in contiguous memory locations 2 (Segment 2) 24 (24 Bytes) Segment No. (s) Displacement (d) s 2048 Bytes (2K) 20480 8192 Bytes (8K) 11264 4096 Bytes (4K) 1024 Length Byte Address 0 1 2 Segment Table Is d > length 1048 1024 Memory Error Yes No Byte address + the displacement gives the physical address Infosys Limited Operating Systems
Version 1.0 30 technique internal fragmentation does not occur as the exact amount of memory is allocated to every segment. For an easy understanding of the address translation the segment number, displacement, length and byte address in the Figure 2-21 are shown in decimal system whereas in reality they are stored in binary (hexadecimal) format.
If simple paging can be compared to the fixed partition scheme, the simple segmentation could be compared to the variable partition scheme wherein the memory is not partitioned into fixed size; instead it is divided into segments of variable length.
Advantages:
x Every individual segment in a job can be protected from the other segments there by preventing any unauthorized access
x Individual segments of a job can also be shared across various jobs. Consider the example of Microsoft Word as an editor which can be loaded as a sharable segment in physical memory so that multiple jobs can access the same
x Prevents internal fragmentation of the physical memory as the exact amount of memory is allocated to each segment
Disadvantages:
x The simple segmentation memory management technique does not support the concept of virtual memory. The size of the physical memory acts an absolute limit to the size of a job.
Similar to Demand Paging technique there is one memory management technique called the virtual segmented system technique which supports virtual memory. In the Virtual Segmented System approach the jobs address space is divided into segments of varying length (as in simple segmentation) and these segments are loaded on demand. In this way every job has a feeling that they have infinite amount of memory available for them. In practice most of the OS which exist today use a memory management technique which is a hybrid of demand paging and segmented system called Paged Segmentation. The functioning of these hybrid memory management techniques are very complex and is the beyond the scope of this study.
2.10. Paged Segmentation Paged segmentation requires two-level translation, segment tables to page tables and then to main memory. Paging leads to internal fragmentation while Segmentation leads to external fragmentation. Trying to reduce external fragmentation increases internal fragmentation and vice versa. Intel 386 and later architecture use segmentation with paging.
Infosys Limited Operating Systems
Version 1.0 31 In Paged Segmentation technique, logical address space of a process is divided into three parts namely Segment Number(S), Page Number (P) and Offset (d). Refer to Figure 1-23 for the discussion on Paged Segmentation. Suppose a process references a virtual/logical address V=(S, P, d), then a search will be performed to locate (S,P). There are three possibilities for it
x If (S,P) found in associative storage(cache memory), page frame is found and moved as per offset to get real memory address. x If (S,P) is not found in associative storage then base address b of segment map table (in primary memory)is found, b is added to segment number S (Say S1), then S1 is added to P to get frame number and finally offset d is added to get real memory address. x If segment map table indicates that segment S is not in primary memory, a segment fault is generated.
Figure 2-22: Segment Table and Address Translation
+ + Segment Table Page Table Main Memory Frame Number Offset Segment Number Page Number Page Frame d Virtual/Logical Address Segment Map Table Segment Number Page Number Offset + + Segment Table Page Table Main Memory Frame Number Offset Segment Number Page Number Page Frame d Virtual/Logical Address Segment Map Table Segment Number Page Number Offset Infosys Limited Operating Systems
Version 1.0 32
Memory Management Technique Advantages Disadvantages Single Contiguous Allocation simple to implement Does not support multiprogramming, leads to CPU time and memory wastage. Fixed Partition Memory Allocation Supports multiprogramming Can lead to internal and external fragmentation of memory Variable Partition Memory Allocation Supports multiprogramming; prevents internal fragmentation Can lead to external fragmentation Re-locatable Partition Allocation Supports multiprogramming; prevents internal and external fragmentation Relocating currently executing jobs is an overhead Simple Paged Allocation Supports multiprogramming; jobs need not occupy contiguous memory locations; prevents external fragmentation Can lead to internal fragmentation
Demand Paging Supports multiprogramming; jobs need not occupy contiguous memory locations; prevents external fragmentation; supports the virtual memory concept Can lead to internal fragmentation Simple segmentation Supports multiprogramming; jobs need not occupy contiguous memory locations; prevents internal fragmentation Does not support the virtual memory concept Table 3: Summary of various Memory Management Techniques
Infosys Limited Operating Systems
Version 1.0 33 3. Process Management Recall that a program that is copied to main memory is called a Job. A Job is also called a Task. A Task is used to refer to a program in execution and the related book keeping 13
information maintained by the Operating System. A program (or a part of it) in execution is also called a process 14 . A process would require resources like CPU time (to execute the program), memory (to store the program), files (to access data), etc. The term job, task and process are synonymous.
The following real world example of cooking would help in understanding the concept of process better.
Figure 3-1: Real world example for process Refer to Figure 3-1 for the following discussion. The cooking manual and all the ingredients for cooking are considered to be passive entities. The act of putting this into action, by cooking, using the cooking manual and the ingredients is the one which produces the desired
13 Book keeping: All additional information which are maintained to describe the task and the resources which it consumes like CPU time, memory, etc. 14 Process: A process is also known as an instance of a program in execution. Multiple instances of the same program can execute simultaneously, for example the mail program. Ingredients for cooking Cooking Manual and ingredients are passive entities and the act of cooking is to put these two into execution Cooking Manual Act of cooking Infosys Limited Operating Systems
Version 1.0 34 dish. The program is analogous to the cooking manual and the process (program in execution) is analogous to cooking. A process requires various resources (like memory, file, etc.) to execute the program.
Process management deals with the various strategies used for managing the different resources which are required for a program to execute. Process management addresses the following questions.
When should a program be brought into main memory? In what order should the various jobs in main memory be processed? What action should be taken when a job is stopped before its completion?
This section covers some of the fundamental concepts of process management. The various techniques used in process management are introduced with a study on their advantages and disadvantages.
The function of process management is to: x Keep track of the status of the various processes in memory x Choose some process for execution based on some criteria x Coordinate communication between various processes and synchronization between these processes 3.1. Structure of a Process Recall from the previous discussion that a program is a set of instructions also called the Code and a Process is a program in execution.
A process maintains information about the contents of the PC and the various registers. A process is said to consist of three regions namely the Code region, Data region and the Stack region. Refer to Figure 3-2 for the discussion on stack.
Figure 3-2: Example of a Stack Stack of Coins P U S H P O P Infosys Limited Operating Systems
Version 1.0 35 A stack is a data structure 15 where the data is removed in the reverse direction in which they are added. So the most recently added data would be the first to be removed. This principle is called Last in First out principle (LIFO). The last element which is added to the collection would be the first to be removed from the collection. Adding an element to the stack is called pushing and removing an element from the stack is called Popping. The pile of coins is stored in the last in first out manner. In a stack the elements are added from one side only. Another example for stack is the pile of plates in a dining hall which are stored in a last in first out manner.
The code region corresponds to the program code. The stack region holds all temporary data (such as the local variables 16 ) and the data region holds all the global data 17 . The word region, segment and section are used interchangeably and mean the same. But why is there a need to distinguish these regions?
Figure 3-3: Structure of a process
Refer to Figure 3-3 for the discussion on process structure. A process is divided into various regions for the following reasons.
x To ensure that there is a level of protection within different modules of the program x To allow sharing of code for multiple instances of the program. For example one could be editing multiple word documents at the same time where in the code region for the word editor is shared across these documents
15 Data Structure: Scheme for grouping related data. 16 Local Variable: Variables which are accessing only in a particular block of the program. 17 Global Data: Variables which are accessing throughout the entire program. Stack Region Data Region Code Region Stack grows downwards Data grows upwards Infosys Limited Operating Systems
Version 1.0 36
The stack region is said to grow downwards and data region is said to grow upwards. What does this mean?
When ever a program is copied into main memory (say from address location 1024 to 1044), the upper part of the programs memory is reserved to store all local variables. This is the stack region. The process starts storing data in the stack region from the highest memory address available for the process (last possible memory location for the process which is 1044). The subsequent data which are stored in the stack region are stored in next memory address which is available just below the earlier one. This way the stack grows downwards and the data region grows in the other direction which is upwards.
This is similar to having the conventional way of writing and the Arabic way of writing in the same line (refer to Figure 3-4). In the conventional way one starts writing from the left whereas in the Arabic writing one starts from the right most corner. The stack region in the process structure is similar to Arabic writing and the data region in the process structure is similar to the conventional writing.
Figure 3-4: Conventional vs. Arabic writing Example 3.2. Process states and state transitions Like human beings a process also has life and goes through a cycle called Process Life Cycle. The various states through which a process goes through during a Process Life Cycle indicates the current status of the process and also provides information on what it is allowed to do next. To understand the Process Life Cycle better consider the following real world example of a fresh graduate joining a software company and undergoing training.
a b c d C o n v e n t i o n a l w r i t i n g A r a b i c w r i t i n g Infosys Limited Operating Systems
Version 1.0 37
Figure 3-5: Real world example for process life cycle
Refer to Figure 3-5 for the following discussion.
A fresh graduate who is offered a job in a software company is in a new state which denotes that he would be new to the industry and to the training. When he joins the company he moves to ready state which denotes that he is ready for the training. The first week of joining the company wherein the software engineer would be spending time finishing all HR formalities would signify the ready state, waiting for training. The software engineer would move to the run state when he actually undergoes his training. When he/she absents himself/herself for more than three days during training, he/she moves to a blocked state (blocked from attending training) from wherein he/she would be asked to join a new batch of training. This means that the software engineer would be moving from blocked state to ready state. If due to business requirements a trainee is pulled out of training abruptly and is asked to join a later batch of training then he/she would move from a run state to a ready state. A trainee on successful completion of training moves to a terminate state which denotes the end of this training. In this example the undergoing training is taken as the execution context.
Ready State New State Run State Terminate State Blocked State Infosys Limited Operating Systems
Version 1.0 38 The above mentioned states are precisely the various states in which a process can exists during the time of its creation till its completion. In other words a process can be in any one of the following states (refer to Figure 3-6).
Figure 3-6: Process states and state transition
New State: A state where the process is created and the OS recognizes the process but no resources are allocated to the process
Ready State: A state where the process is ready for execution and is waiting for CPU time
Run State: A state where in the process (the instructions in the program) is actual being executed
Blocked State: A state where in a running process does not have immediate access to a resource and waiting for some event to occur, like waiting for an input from the keyboard Terminate State: A state where the process has finished its execution
The next obvious question would be on the need for transition from one state to another in a process? What significance does this state information have?
Consider a scenario where in there is a word document and a calculator open in a computer system (refer to Figure 3-7). While editing the word document, the user can suddenly switch to the calculator application and when the user returns to the word document he has to continue from where he left. The word document which was in a running state goes to a blocked state till the user finishes the calculator application (the current context of the word document is saved) and when the user returns to the word document the saved context is loaded. Transition from one state to another helps the OS to switch from one process to New State Ready State Run State Blocked State Terminate State admitted gets CPU time interrupted waits for an input input completed exit Infosys Limited Operating Systems
Version 1.0 39 another. This act of the OS is called context switching. When ever a context switch happens the state of the current process is saved so as to ensure that when this process returns back for execution it continues from where it had left.
The context switch is done to keep the CPU busy all the time by running at least one process. Context switching occurs when:
The process issues an input/output (I/O) request. In this case the process goes from Run to Block state The process is interrupted by some other process. In this case the transition is from Run to Ready. The process finishes an input/output (Block to Ready) The process terminates (terminate)
Figure 3-7: Context Switching Context Switching Infosys Limited Operating Systems
Version 1.0 40
Notice that there could be more than one process waiting for execution. In Figure 3-7 there is word document and the calculator process. How does the OS keep track of the various processes which are waiting for execution? Do the process states help the OS to keep track of various processes? If yes then how?
The OS (Process Manager) maintains a Queue to keep track of the various processes. What is a queue? Refer to Figure 3-8 for the discussion on queue.
Figure 3-8: Example of a Queue
A Queue is a data structure (organization of data) where the data is added at one end and is removed at the other end. The first element which was added to the collection of data would be the first to be removed. The Figure 3-8 shows a set of people standing in a queue to reserve tickets. A queue data structure uses the first in first out (FIFO) principle.
All the processes which are waiting for execution are maintained in a queue by the process manager. Since the processes can be in different states during their life cycle, the process manager uses different queues to distinguish the processes based on their states. When a new Queue Infosys Limited Operating Systems
Version 1.0 41 process is created it enters a job queue and when it is ready for execution it is moved to a ready queue. Similarly when a process is waiting for an I/O operation it is moved to an I/O queue.
3.3. Multiple Processes Multiple processes can reside in memory and these processes would be in one of the process states mentioned earlier. The process manager maintains different queues for these processes. What kind of relationship do these processes have?
Processes are broadly categorized into two based on their interaction with the other processes. These two categories are discussed below:
Figure 3-9: Example for Independent and Cooperating Processes
Independent Process: An independent process is one which does not affect other processes and neither does it get affected by them. Taking the final examination is an example of independent process (refer to Figure 3-9).
Cooperating Process: A cooperating process is one which shares some information or communicates with other processes in order to speed up the computation time. Working on a project as a team is an example of a cooperating process (refer to Figure 3-9). 3.4. Inter Process Communication Communication between cooperating processes is called Inter Process Communication (IPC). Cooperating processes communicate by one or more of the following ways:
Sharing a portion of memory among them where in the information to be communicated is put so that the other processes can read from there. This mechanism is called shared memory concept. An example of shared memory would be the bulletin board (refer to Figure 3-10). Exam Project Infosys Limited Operating Systems
Version 1.0 42
Figure 3-10: Example for IPC using shared memory
Passing messages across these cooperating processes. This mechanism is called Message Passing concept. An example of message passing would be the mail application (refer to Figure 3-11)
Figure 3-11: Example for IPC using Message Passing
Bulletin Board Mail Infosys Limited Operating Systems
Version 1.0 43 Sending signals to other processes. This mechanism is called Signal Processing concept. IPC using signals would be used only to convey minimal information. An example for signal processing would be the traffic signal (refer to Figure 3-12)
Figure 3-12: Example for IPC using signals 3.5. Multiprogramming, Multiprocessing and Multitasking Recall that Uniprogramming is a scenario wherein the OS allows only one process to reside in memory.
Multiprogramming: The ability of the OS to have multiple programs in memory which are ready for execution is called Multiprogramming. The term Multiprogramming is normally associated with a Uniprocessor system 18 .
Multiprocessing: Multiprocessing in simple terms mean multiple processes executing simultaneously. The term multiprocessing is normally associated with a multiprocessor system (one which has multiple CPUs so that multiple processes can execute simultaneously).
Multitasking: The act of switching the processor from one process to another process is called multitasking, i.e. multitasking is a result of context switching. In a multitasking system there is only one processor and at a given point of time there is only one program in execution and other programs potentially can run.
18 Uniprocessor System: Computer Systems which have a single processor. Signal Infosys Limited Operating Systems
Version 1.0 44
Figure 3-13: Example for multiprogramming, multiprocessing and multitasking The telephonic conversation example mentioned in Figure 3-13 would help in better understanding of multiprogramming, multiprocessing and multitasking. The call waiting facility available in the telephone is similar to multiprogramming. Due to the call waiting facility there could be multiple calls coming to a particular number at the same time. This is similar to multiprogramming wherein multiple processes (in ready state) are held in memory at a given time. The act of switching the conversation from one caller to another caller is nothing but multitasking. Attending to multiple telephone calls at the same time is similar to multiprocessing. Note that the telephone in this example is analogous to the CPU in the computer system.
Note: The ability of the operating system to hold multiple programs in the ready state (to store more than one process) in memory at a time is called multiprogramming whereas the actual act of switching of the processor between these ready jobs based on a policy is called multitasking
How is multitasking implemented?
A program called Scheduler, which is part of the OS, switches between one process to another at different instances of time. Whenever a process goes into a blocked state its current context (state information) is saved and the scheduler does a context switch by loading another process for execution. The meeting request in the mail program has a scheduler which helps in viewing the calendar of others (refer to Figure 3-14).
Conversation is on Call waiting Multiprocessing Infosys Limited Operating Systems
Version 1.0 45
Figure 3-14: Example for scheduler
3.6. Types of Multitasking The different types of multitasking are:
Cooperative Multitasking: In this kind of multitasking, which is very primitive, the responsibility for releasing control of the CPU is placed on each and every process that is executing. In this case the process has to voluntarily give up the CPU and normally the CPU is taken up by the process for longer periods of time. A real world example for cooperating multitasking would be checking in to a hotel (refer to Figure 3-15). There could be many people waiting to book a room (synonymous to CPU time) but the current person who has checked in can continue to stay in his room as long as he wishes too. Only when he voluntarily checks out the other people would be allotted this room.
Infosys Limited Operating Systems
Version 1.0 46
Figure 3-15: Example of cooperating multitasking
Preemptive Multitasking: This kind of multitasking ensures that every process gets a chance to run. Preemptive multitasking allows each process to run till it voluntarily relinquishes the CPU or till a fixed duration of time. When the fixed time duration expires the OS preempts the currently running process. A real world example for preemptive multitasking would be the paid parking of vehicles for a fixed time slice (refer to Figure 3-16). Moment the time duration is over (say parking for one hour) the vehicle is removed from the parking lot by the authorities.
Figure 3-16: Example for Preemptive Multitasking
Non-preemptive Multitasking: In this kind of multitasking, the process which is currently given the CPU time would be allowed to run until it terminates or when it waits for an I/O. Note the difference between cooperative and non-preemptive multitasking. In a cooperative multitasking OS, the currently executing process need not relinquish the CPU even when it waits for an I/O. A real world example for non-preemptive multitasking would be cars moving on a highway (refer to Figure 3-17). A car continues to run as long as it wants but the moment it breaks down (synonymous to waiting for I/O) this car is towed away from the highway which is similar to relinquishing the CPU. Hotel Paid Parking Infosys Limited Operating Systems
Version 1.0 47
Figure 3-17: Example of Non-preemptive Multitasking
3.7. Threads A thread is a basic unit of execution. A thread is a single sequential flow of control within a program. A thread is also known as a light weight process. A process can have many threads of execution.
What structure does the thread have? Recall that a process is a program in execution and the process structure is divided into code region, data region and stack region. Since a thread is a unit of execution (part of the process) it has the code region, data region and stack region. The code region and data region of a process are shared across different threads of the same process (refer to Figure 3-18). Each thread of a process has its own stack region and PC.
Towing Infosys Limited Operating Systems
Version 1.0 48
Figure 3-18: Thread Structure
Why is there a need for multiple threads in a process? Consider the following real world example of a editing a document using an editor 19 . This editing would be executed as a thread in the process. Suppose that the user also wants to use the spell check facility available with the editor. If the OS allows only one thread for each process (single threading 20 ) then the user should first finish editing the document and then use the spell check facility. This would be time consuming and also during the course of editing the CPU would be idle most of the times.
Allowing multiple threads to execute concurrently 21 in this case would improve the CPU utilization and also the spell check can be done as and when the document is edited. Figure 3-19 illustrates multithreading concept in the word editor. The spell checker runs concurrently as and when the user edits the document.
19 Editor: A program which helps in editing programs and documents. Microsoft word is an example of an editor. 20 Single threading: Allowing only one thread per process. 21 Concurrently: Parallely. Process Thread 1 Thread 2 Thread 3 Stack Region Data Region Code Region Stack Region for Thread 1 Stack Region for Thread 2 Stack Region for Thread 3 Stack Region of the Process Infosys Limited Operating Systems
Version 1.0 49
Figure 3-19: Example of multithreading
Another good example for multithreading would be the web browsers 22 . As the browser fetches a document it will also concurrently allow the user to interact with the existing information in the browser.
22 Web browser: A software program that lets the user to find, see and hear material on a the world wide web which is a communication medium. Infosys Limited Operating Systems
Version 1.0 50
Figure 3-20: Browser example for multithreading
Advantages of multithreading:
Multiple threads in a process share the same memory address space. This means memory utilization would be bettered by using multithreading
Concurrent execution of threads would result in faster execution of the process 3.8. Scheduling The basis for multitasking is Scheduling. Determining when a given process is to be run, within a multitasking environment is called Scheduling.
Some of the important criteria based on which the scheduling policy (or algorithm) is chosen are mentioned below. These criteria are explained with the help of a real world example of a user standing at a railway reservation counter and waiting to get his ticket reserved (refer to Infosys Limited Operating Systems
Version 1.0 51 Figure 3-21). Here the users standing in the queue are synonymous with processes and the reservation clerk is synonymous with CPU.
Figure 3-21: Reservation Counter example
CPU Utilization: This gives a measure of what percentage of the CPU is being utilized. A scheduling algorithm should be chosen such that the CPU utilization is high. With respect to the ticket reservation example this would refer to the percentage utilization of the reservation clerk.
Throughput: This measure indicates the number of processes executed per unit of time. A good scheduling algorithm is one which has a higher throughput. With respect to the ticket reservation example this would translate to the number of users processed in a given unit of time by the reservation clerk.
Turnaround Time: This is a measure which gives the amount of time taken by a process for its execution. This includes the time spent by the process waiting for main memory, time spent waiting in the ready queue, time spent in executing on the CPU and the time spent doing an I/O. A good scheduling algorithm is one which has a lesser turnaround time for processes. In the ticket reservation example this measure would refer to the total amount of time a user spends from the time of entering the reservation block till the user gets his tickets booked. This would include the time the user spends in filling in the reservation form, waiting in the queue, answering the queries from the reservation clerk and finally getting the tickets issued.
Waiting Time: This is a measure which gives the amount of time spent by the process waiting in the ready queue. This measure does not take into account the time spent in I/O. A good Will I get my ticket? / Infosys Limited Operating Systems
Version 1.0 52 scheduling algorithm is one which reduces the waiting time for a process. In the ticket reservation example this would refer to the time which the user spends waiting in the queue.
Response Time: The time taken from submission of a process until the first response is called Response Time. This measure is very useful in Interactive Computer Systems 23 . A good scheduling algorithm is one where the response time for each process is as least as possible. In the ticket reservation example this would refer to the time spent by the user in the queue till the user gets the first response from the reservation clerk. This response need not necessarily be the reserved tickets. It could be a response like the status is waitlisted. Do you still want to book a ticket?
A good scheduling algorithm is one which has a high CPU utilization, maximum throughput, minimum turnaround time, minimum waiting time and least response time. 3.8.1. Types of Scheduling Broadly the scheduling policy is of two types:
Non-preemptive scheduling: In non-preemptive scheduling, a process which is allotted the CPU time will continue to run until it terminates or until it gets blocked due to an I/O request. In this scheduling the process cannot be forced to relinquish the CPU time. An example of non-preemptive scheduling is the First Come First Serve (FCFS) scheduling policy. Here the process is allotted the CPU time based on the order in which it enters the ready queue. An example of FCFS is the railway reservation counter mentioned in Figure 3-21.
One of the main disadvantages of the FCFS scheduling algorithm is the monopoly 24 of a process. This would mean that a single process might take all of the CPU time without relinquishing the same. In the railway reservation counter example this would mean that the current person who is booking the ticket might take most of the time of the reservation clerk by enquiring about various trains and their availability.
23 Interactive computer systems: Computer systems which interact with the user during the course of execution of a program. 24 Monopoly: controlled by one party. Infosys Limited Operating Systems
Version 1.0 53 Consider the following illustration for FCFS scheduling policy.
Process Estimated runtime (in milliseconds) P1 6 P2 8 P3 7 P4 3
Table 4: Illustration for FCFS scheduling algorithm The Table 4 shows four process (P1, P2, P3 and P4) waiting in the ready queue for the execution. These processes would be executed in the order in which they entered the ready queue, i.e. P1 followed by P2 followed by P3 followed by P4 as shown in the Gantt Chart shown in Figure 3-22. To find out the efficiency of the FCFS scheduling algorithm the average waiting time is calculated.
Figure 3-22: Gantt chart for FCFS -Example The waiting time for P1 = 0 milliseconds (P1 starts executing first) The waiting time for P2 = 6 milliseconds (P2 starts executing after P1) The waiting time for P3 = 14 milliseconds (P3 starts executing after P1 and P2) The waiting time for P4 = 21 milliseconds (P4 starts executing after P1, P2 and P3)
Hence the average waiting time = (0 + 6 + 14 + 21) / 4 = 41 / 4 = 10.25 milliseconds Turn Around Time(TAT) for P1 is = 6; P2=14; P3=21; P4=24.
Hence the average TAT is =65/4 =16.25
Note: Average TAT can also be calculated as average waiting time +average execution time. So in this example the average waiting time =7ms and the average execution time =24/4=6; Hence average TAT=13ms.
Version 1.0 54 The Average response time can be calculated as follows: Response time for P1=0, P2=6, P3=14,P4=21. Hence Average response time is equal to 10.25 milliseconds.
Preemptive scheduling: In preemptive scheduling a process which is currently running can be removed from the running state by the scheduler in order to allow another process to run. This act of the scheduler is Preemption 25 . One mechanism of preemptive scheduling would be to specify a fixed time slice 26 during which a process gets CPU time. If the time slice is 4ms (milliseconds) and a process gets its time slice, then this process is executed in 4ms and then another process is given the CPU time. If the original process terminates before 4ms then the CPU will immediately make a context switch which ensures that another process is given the CPU time. Some scheduling algorithms are discussed below with illustrations 3.8.2. Shortest Job First (SJF) Algorithm The SJF algorithm schedules the processes based on their given estimated run time. The process with the shortest estimated run time would be scheduled first followed by the next shortest and so on. The following real world example (Refer to Figure 3-23) would help in better understanding of the SJF algorithm.
Figure 3-23: Example for SJF algorithm
Consider the scenario wherein water needs to be filled in a glass and a bucket from a single tap. Since the glass is of smaller size the water would be filled in the glass first and then followed by the bucket. This is nothing but shortest job first execution. Water from the tap is similar to the CPU and the act of filling in water into the glass and bucket are similar to two different processes.
25 Preemption: Taking possession of CPU before the currently running process relinquishes the same 26 Time Slice: A quick period of time in which a process is given to access the CPU Bucket Glass Infosys Limited Operating Systems
Version 1.0 55 Consider the following illustration for SJF algorithm.
Process Estimated runtime (in milliseconds) P1 6 P2 8 P3 7 P4 3 Table 5: Illustration for SJF algorithm The Table 5 shows four process (P1, P2, P3 and P4) waiting in the ready queue for the execution. These processes would be executed based on their estimated run time. The process with the least estimated run time requirement would be executed first followed by the next least and so on. i.e. P4 followed by P1 followed by P3 followed by P2 as shown in the Gantt chart in
Figure 3-24: Gantt chart for SJF -Example The average waiting time for the four processes when the SJF algorithm is used is calculated as follows:
The waiting time for P4 = 0 milliseconds (P4 starts executing first) The waiting time for P1 = 3 milliseconds (P1 starts executing after P4) The waiting time for P3 = 9 milliseconds (P3 starts executing after P4 and P1) The waiting time for P2 = 16 milliseconds (P2 starts executing after P4, P1 and P3)
Hence the average waiting time = (0 + 3 + 9 + 16) / 4 = 28 / 4 = 7 milliseconds
Accordingly the average TAT will be 52/4=13 milliseconds (better than FCFS).
Average Response time is calculated as follows: P1=3; P4=0; P3=9; P2=16. Hence Average Response time=28/4=7 milliseconds, which is much better than FCFS.
In general SJF scheduling algorithm is better than FCFS scheduling algorithm as the average waiting time is less for SJF scheduling algorithm. The key point to note in SJF scheduling P1 P2 P3 P4 6 8 7 3 0 3 9 16 24 Infosys Limited Operating Systems
Version 1.0 56 algorithm is that by moving the shorter process before a longer process, the waiting time of the shorter process decreases more than the increase in the waiting time for the longer process.
What if a new process (P5 with CPU time as 2 ms) arrives into the ready queue when P1 which is currently being executed using the SJF scheduling algorithm has finished 1 ms of its CPU time i.e., at 4 th instance of time?
Interesting scenario! The SJF scheduling algorithm could either be preemptive or non- preemptive scheduling algorithm.
If SJF scheduling algorithm is non-preemptive then as soon as P1 terminates P5 is scheduled.
Normally there are two categories of Jobs that get into the ready queue. First category is that of the CPU bound Jobs and the other category is that of the I/O bound jobs. CPU bound jobs are those which take a lot of CPU time but spend very less time in doing the I/O operations. On the other hand the I/O bound jobs are those which take very less CPU time, but spend a lot of time doing I/O operations like printing, receiving input from the keyboard, etc. If there are two processes in the ready queue, one being CPU bound and the other one being I/O bound, then the I/O bound process which takes less CPU time could be preferred to be executed first and released to do its I/O operation. This would result in lesser average waiting time.
If SJF scheduling algorithm is preemptive then the scheduler checks whether the CPU time of P5 is shorter than what is the remaining of the total estimated time of the currently executing process P1. P1 has still 5 ms of CPU time left over. Since P5s CPU time is shorter, P1 is preempted before it could complete its execution and P5 is executed as shown in Figure 3-25. In such a case, the average waiting time would become (0+3+0+2+11+18)/5= 34/5 =6.8 milliseconds, whereas average turnaround time would be (3+(6-4)+11+18+26)/5= 60/5 = 12 milliseconds. Preemptive SJF scheduling algorithm is also called as Shortest Remaining Time scheduling (SRT) algorithm.
Figure 3-25: Gantt chart for SJF -Preemptive The main disadvantage of SJ F scheduling algorithm is that more often it is difficult to know the next shortest process in the ready queue as new processes keep entering the ready queue. Also a process which requires more CPU time may never get the CPU at all. This is called as Starvation or Live Lock. In the above example, if more and more processes of time duration P1 P2 P3 P4 5 8 7 3 0 3 11 18 26 P5 P1 4 5 1 6 Infosys Limited Operating Systems
Version 1.0 57 almost equal to P5 keep entering the ready queue, then the processes P3, P4 may never get a chance to get executed by the CPU. 3.8.3. Round Robin (RR) Algorithm The RR algorithm is primarily designed for operating systems where multiple users use the CPU time in such a way that every user feels that they have the whole computer for themselves. Such systems are called time sharing systems. The RR scheduling algorithm is similar to FCFS scheduling algorithm, except for the fact that preemption is added to switch between processes. In this scheme, a time slice (generally 10 to 100 milliseconds) is defined. The ready queue is considered to be a circular queue 27 . The scheduler goes around the ready queue, allocating the CPU to each process for a time interval of up to 1 time slice.
Recall that a queue works on the principle of First in First out (FIFO). New processes are added to the other end of the ready queue. The scheduler picks the first process from the ready queue and schedules it for execution.
Now if the process terminates before the elapse of the time slice, then the process itself will releases the CPU voluntarily. The scheduler will now proceed to next process in the ready queue. On the contrary if the process does not finish its execution during its allotted time slice then a context switch is done by the OS and the next process in the ready queue will be executed. This incomplete process which was preempted would be put at the other end of the queue.
The advantage of RR scheduling algorithm is that it ensures every process gets a fixed amount of CPU time unlike FCFS algorithm where there could be processes waiting for CPU time for quite a long time.
Calculate the Average waiting time with respect to Round Robin Scheduling with Time Slice = 3 for the processes as shown in
Process Estimated runtime (in milliseconds) Arrival Time P1 12 0 P2 10 0 P3 4 1 P4 10 4 P5 12 2 Table 6: Processes to be scheduled Solution: Refer Figure 3-26 . The average waiting time is calculated as follows:
27 Circular queue: A type of queue where in the last element in the queue is connected back to first element of the queue. Infosys Limited Operating Systems
Version 1.0 58 Waiting time for P1 =0+(15-3)+(28-18)+(40-31)=31, P2=3+(18-6)+(31-21)+(43-34)=34, P3=(6- 1)+(21-9)=17, P4=(12-4)+(25-15)+(37-28)+(47-40)=34, P5=(9-2)+(22-12)+(34-25)+(44-37)=33. Hence average waiting time is equal to (31+34+17+34+33)/5= 29.8 milliseconds. Note that P3 arrives at instance 1. Accordingly for the first slice the waiting time is (6-1). The rest of the calculation is self explanatory.
Figure 3-26 : Gantt chart for Round Robin Scheduling Calculating the Average turnaround time and response time is left as an exercise. The disadvantage of RR scheduling algorithm is the overhead involved in maintaining the time slice information for every process which is currently being executed.
3.8.4. Priority Scheduling In priority scheduling, each process is assigned a priority 28 number which indicates a rating of these processes when compared to each other. This number is used in deciding which process should be scheduled. Consider the following real world example of vehicles moving in a road (refer to Figure 3-27). Compared to other vehicles on the road an ambulance has a higher priority. Whenever an ambulance comes on a road all other vehicles need to give way for the ambulance because of its higher priority.
Figure 3-27: Example for Priority Scheduling
Similarly in priority scheduling the process with the highest priority is selected for execution. Priority scheduling can be either preemptive or non-preemptive.
In preemptive priority scheduling whenever a higher priority process arrives the currently executing process is preempted and the new process is assigned the CPU time. The ambulance example mentioned in Figure 3-27 is an example of preemptive priority scheduling.
Calculate the Average waiting time with respect to Priority based preemptive Scheduling (Assume priority 0 is greater than 1). In case of any tie, use FCFS
Process Estimated runtime (in milliseconds) Arrival Time Priority P1 12 0 2 P2 10 0 1 P3 4 1 0 P4 10 4 2 P5 12 2 1
Solution: Average Waiting Time=14. Refer Figure 3-28 for explanation. The average waiting time = (26+(0+4)+0+(38-4)+(14-2)) /5 =76/5=15.2 milliseconds and the turn around time will be =24.8 milliseconds.
Figure 3-28: Gantt chart for Priority based Preemptive Scheduling
In a non-preemptive priority scheduling the currently executing process is not disturbed whenever a new higher priority process arrives. This higher priority process is placed at the beginning of the ready queue so that it could be scheduled for execution as soon as the currently executing process terminates. The following real world example would help in better understanding of non-preemptive priority scheduling.
Figure 3-29: Example for non-preemptive priority scheduling
Refer to Figure 3-29 for the following example on a gents saloon. When the barber is doing a hair cut for a boy a VIP arrives for shave. Since the barber cannot stop the hair cut in the middle he requests the VIP to occupy the first position in the queue (as he is a VIP) and first finishes his job with the boy. The barber is synonymous with the CPU. The boy who is having his hair cut is synonymous with the currently executing process and the VIP who arrives is synonymous with a new high priority process that arrives.
Disadvantage: The main disadvantage in priority scheduling is that it can cause a low priority process to wait in the ready queue for an indefinite time hence causing starvation.
Consider the example mentioned in Figure 3-29. If more and more VIPs come to this barber then the two people who are already waiting in the queue would be left waiting for an indefinite amount of time as the VIPs will always occupy the front position in the queue. This is called as Starvation.
One solution to this problem is to slowly increase the priority of a process which is waiting in the ready queue for a longer time. This will ensure that the low priority process will also eventually get executed as its priority would increase gradually. This technique of slowly Queue URGENT! I am a VIP Please occupy the first position in the queue sir!!. I need to first finish my job with this boy Infosys Limited Operating Systems
Version 1.0 61 increasing the priority of processes which are waiting in the ready queue for long time is called aging.
The aging technique when applied to the example mentioned in Figure 3-29 would ensure that the two people who are waiting in the queue for a longer duration of time will also get serviced by the barber.
3.8.5. Multi Level Queue Scheduling When there are many processes with various levels of processing, it needs complex scheduling. The workload has to be classified according to processes characteristics. The process management has to maintain separate process queues serviced by different schedulers. For example, the division of workload might be done as System processes, Interactive programs and Batch jobs. This will result in 3 three ready queues as shown in Figure 3-30 The processes from the highest priority queue are serviced until that queue becomes empty. The scheduling policy is priority based pre-emptive scheduling. When the first queue (highest-priority) becomes empty, the next queue may be serviced using RR policy. When both the above queues are empty, the third (lowest-priority) queue is serviced using FCFS. A lower priority process may be preempted when a higher-priority process arrives in one of the upper-level queues.
Figure 3-30: Multi-level queue scheduling
Multilevel Feedback Queue (MFQ) has more than one queue and a process can move between one queue to another queue. Multilevel-Feedback-Queue scheduler is defined by the following parameters. x number of queues in MFQ
CPU System Interactive Batch Priority based pre- FCFS Round Infosys Limited Operating Systems
Version 1.0 62 x scheduling algorithms for each queue x method used to determine the following o In which queue a process will enter o when to upgrade a process o when to demote a process Aging can be achieved by moving the process from one queue to other. For example, consider three queues Q0, Q1, Q2 with the following scheduling algorithms. x Q0 RR with time quantum 6 ms x Q1 RR with time quantum 12 ms x Q2 FCFS Say, a new process enters queue Q0. In Q0, the algorithm is RR with time quantum of 6 ms. When the CPU is allocated to Process it will be served for 6 ms. If process will not be finished in 6 milliseconds, it will be preempted and process will move to queue Q1. In Q1 process will be served again using RR algorithm, with a time quantum of 12 ms. If still, it will not complete, it will be preempted and moved to queue Q2. In Q2, process will be served using FCFS algorithm.
Figure 3-31: Multilevel feedback queue
Infosys Limited Operating Systems
Version 1.0 63 3.9. Process Coordination A cooperating process is one which shares some information or communicates with other processes in order to speed up the computation time. Files provide one mechanism for sharing information. Amount of information that can be shared using files are limited by the file capacity of the file system. The file system management is described in Section 4.
Another mechanism used for information sharing is through the shared memory. The shared data is called critical resource and the portion of the program which uses this critical resource is called critical section. In the Figure 3-32, the processes P1 and P2 are sharing the same memory Location. But at any point in time either P1 or P2 can access this memory location. When P1 is accessing this memory as in Figure 3-32, P1 is said to be in critical section, and so P2 cant access this memory location. If the processes are managed in a way that access to the shared memory location by a process negates accesses to this memory location by any other process, such a condition is called mutual exclusion. A number of solutions are available to implement mutual exclusion. They are as follows: 1. Software solutions: Dekkers Algorithm, Petersons Algorithm, Bakery Algorithm 2. Hardware solutions: Special machine instructions would provide the solution 3. Operating System solutions: Data structures and functions can be provided to programmer through system calls or library calls. Semaphores provide a general- purpose solution to controlling access to critical section. The concept of Semaphores is provided in Section 3.9.1 4. Programming Language solutions: Programming language constructs can be provided to programmer.
Figure 3-32: Mutual Exclusion
Shared Memory
P1 Mutual exclusion P2 P1 accessing the memory locations
Infosys Limited Operating Systems
Version 1.0 64 3.9.1. Semaphores In 1965, Dijkstra, a Dutch computer scientist and Turing Award winner, proposed the use of an abstract data type called a semaphore for controlling access to critical sections by relating the concept of semaphores used in the rail industry to the problem of task synchronization in computer systems. He considered platform as shared resource and two trains as two tasks. Tasks use the shared resource like how the Trains use the platform. Like how, only one train can use the platform at a given time, only one task can use a shared resource at a time. To control the traffic, the trains are synchronized with the help of Semaphores. Dijkstra therefore, conceptualized that the tasks could be synchronized with the help of Semaphores. He first used the term seinpaal a dutch term for signal-pole. When applied specifically in vernacular of Rail Domain, it becomes semafoor in Dutch. As the railroad semaphore has two states, wait and proceed or raise and lower, it is called a binary semaphore.
Figure 3-33: Use of Semaphores in rail industry for Synchronization
A semaphore in general is defined as a simple integer variable which can take non-negative value and upon which two operations called(s) and signal(s) are defined. Semaphore indicates the availability of a resource. Non-zero positive value of s indicates that resource is available. Zero value of s indicates that resource is Unavailable. Wait allows a task to access the resource and signal indicates that the resource has been released by the task.
A good example to demonstrate the use of semaphores for multi process synchronization is the Producer-Consumer problem. This problem involves two processes, namely a producer process and a consumer process. Both producer and consumer share a common bounded/fixed-size buffer. The job of producer is to generate a piece of data and put it into the buffer one piece at a time. Job of consumer is to consuming the data i.e. removing it from the buffer one piece at a time. The problem is to make sure that the producer should not try to add data into the buffer if the buffer is full and the consumer should not try to remove data from buffer if the buffer is empty. Both producer and consumer process should Infosys Limited Operating Systems
Version 1.0 65 not access the buffer simultaneously, so we require to make some provision to guarantee Mutual Exclusion. When buffer is full, Producer must wait for an Empty Space. When buffer is Empty, Consumer must wait for Data Available. The question is that, to solve this problem how many semaphores are required? A semaphore with initial value n would be needed to keep track of the space available in the buffer. A binary semaphore with initial value 0 would be needed to indicate whether data is available (value 1) or not (value 0). And, another semaphore with initial value 1 would be needed guarantee the mutual exclusion for buffer access. Although semaphores provide a general-purpose mechanism for controlling access to critical section s, their use does not guarantee that deadlock will be avoided. The concept of deadlock and the mechanisms to break the deadlock have been explained in Section 3.9.2
3.9.2. Deadlocks A deadlock refers to a specific condition when two or more processes are waiting for each other to release a resource. A deadlock will occur in a computer system if all the following conditions hold simultaneously. 1. Mutual Exclusion means that a resource is assigned to only one process at a time. 2. Hold and wait condition means a situation where in a process owns a resource and claiming the other resource. 3. No Preemption condition means a situation where the granted resource to a process cannot be taken back by the operating system forcibly. 4. Circular Wait is a situation where each waiting process is waiting for the next process in the chain and none is able to get the resource. All the above four conditions must be met in order for a deadlock to occur.
There are basically four ways the deadlock situations can be handled. 1. Ignore the deadlock: This is the simplest strategy amongst all which is based on the thought to pretend that deadlock will never occur in the system. This is called as Ostrich Algorithm. The algorithm derived its name from the behavior of the Ostrich, as they stick their head in the sand and pretend that there is no problem. This strategy for deadlock handling will be useful if the deadlocks occur very rarely and the cost of prevention is high. In other words, the strategy is based on the tread off between Convenience, Cost and Correctness.
2. Avoid the deadlock: Deadlock can be avoided if certain information about processes is available prior to resource allocation. For every resource request, the system checks that if granting the request will mean that the system will enter an unsafe state, that is, a state that could result in a deadlock. The system only grants requests that will not lead to an unsafe state. One known algorithm that is used for deadlock avoidance is the Banker's algorithm. This algorithm requires resource usage limit to be known in advance. The name is by analogy with the way that bankers account for liquidity Infosys Limited Operating Systems
Version 1.0 66 constraints. This strategy for deadlock handling will be useful if the operating system is available in advance at any time with following information: x The number and type of all the existing processes x Existing resources and x The resources requested 3. Prevent the deadlock situation from happening: As there are four basic conditions that must be met in order for a deadlock to occur, preventing any one not to happen will prevent the deadlock eventually. Removing the mutual exclusion condition requires that no process may have exclusive access to a resource. Practically this is rather difficult to achieve, as mutual exclusion is necessary for concurrent processes. Hold and Wait can be prevented if a process is not allowed to request a resource during its execution rather the process is required to requests all of its required resources at the start of its execution. If all the requested resources are available then the operating system allocates all such requested resources to the process and process is allowed to execute. This prevents the deadlock to happen. There are two ways in which the operating system can break the necessary condition of "no Preemption" for a deadlock to occur. x If a process holding certain resources and is denied for a further request by the operating system, that process must release its original resources. x If a process requests a resource that is currently held by another process, the operating system may preempt the second process depending up on the type and/or the priority of the process and release its resources Circular wait prevention consists of allowing processes to wait for resources, making sure that the waiting can't be circular. One approach might be to assign precedence to each resource and force processes to request resources in order of increasing precedence. That is if a process holds some resources, and the highest precedence of these resources is K, then this process cannot request any resource with precedence smaller than K. This makes resource allocation to result in a particular and non- circular ordering, so that circular wait cannot occur. Deadlock prevention is used if: x The resources can be spooled x If all-or-none resource allocation policy is allowed x If overhead of pre-emption is low, and x If linear order amongst the resources can be done
4. Detect and Recover from deadlock: Even applying any of these strategies deadlock may occurs. In such instances it becomes necessary for the operating system to detect the deadlock and recover from that. x Invalidating one of the four conditions: Once a deadlock has been detected, one of the four conditions must be invalidated to remove the deadlock. Generally, the operating system removes the circular wait by terminating a process waiting for the longest period of time. Infosys Limited Operating Systems
Version 1.0 67 x Implementing check pointing and rollback: Some operating systems facilitate deadlock recovery by implementing check pointing and rollback. Check pointing is saving enough state of a process so that the process can be restarted at the point in the computation where the checkpoint was taken. If a deadlock is detected, one or more processes are restarted from their last checkpoint this is called as rollback. Deadlock recovery is generally used when deadlocks are rare, and the cost of recovery (process termination or rollback) is low. The resource usage plays a central role in deadlocks. Deadlocks are inevitable, so the operating system must be able to prevent the computer system from it, and even if it occurs the operating system must be able to detect and recover from it.
Infosys Limited Operating Systems
Version 1.0 68 4. File System Management Most of the computer applications use the storage features provided by the secondary devices. Recall that the secondary devices provide a huge amount of storage which is non- volatile and also relatively cheaper. The part of the operating system that deals with effective information management is called as file system 29 management. The term file is used for anything that is stored in the secondary storage. A file could be a program (source code or executable), text files, word documents, image files, audio/video files etc. Each of these files differs in the kind of information they hold and also the way in which the information is stored.
The file system management of the OS deals with managing these files and in providing a consistent mechanism for the user to access these files.
The desirable features of a file system are as follows:
Provide minimal input and output operations on the files to access the information stored in them Isolate the differences between the actual physical storage of these files and the one which the end user sees when he/she accesses these files Provide automatic allocation of file space based on the amount of free space available Provide a flexible naming convention for these files
The file system management of two well known file systems, namely MS-DOS file system and UNIX file system, are discussed in this section. 4.1. MS-DOS File System The file naming convention in DOS consists of a logical drive 30 , path and filename. The following examples would help in better understanding of above mentioned terms.
Consider the example of a cupboard (refer to Figure 4-1) which is synonymous with a physical hard disk whereas the various partitions inside a cupboard is synonymous with the logical drives in a hard disk.
29 File System: The structure by which files are organized, named and stored in an OS. 30 Logical Drive: The internal division of a large hard disk into smaller units. Normally one single physical drive is divided into several logical drives. Infosys Limited Operating Systems
Version 1.0 69
Figure 4-1: Example for Physical vs. Logical Drive
Consider the following example shown in Figure 4-2. Suppose that the CHSSC.doc 31 is a file which is placed in a particular location, say C:\CHSSC\coursematerial. Then C: refers to the logical drive name and C:\CHSSC\coursematerial is called the path name. The path specifies the location in the logical drive wherein the file is present. The path could be thought of as the route which one specifies to reach a particular destination. There could be multiple logical drives in an OS, for example C:, D:, etc.
Figure 4-2: Example for file naming convention in MS-DOS
In the above example CHSSC and coursematerial are called directories. A directory is a logical grouping of files. In other words a directory is a collection of files which are related to a user or an application.
31 CHSSC.doc: Files with .doc as their extensions are called document files. Cupboard Logical partitions in the cupboard C: Refers to the logical drive C:\CHSSC\coursematerial Refers to the path name Infosys Limited Operating Systems
Version 1.0 70
Why is there a need to group files into a directory?
The following real world example (refer to Figure 4-3) would help in understanding the need for a directory.
Figure 4-3: Example for Directory
In a filing cabinet the various files are organized based on their category. For instance confidential files are organized in one place; files related to employee details are organized in one place. This organization helps in protecting the files (by putting some restrictions) and also helps in accessing all the related information much faster. The example of a library or dictionary could also be considered for understanding the need for a directory.
The files are organized on each logical drive within a hierarchical 32 directory structure called a tree. A tree is a hierarchical data structure using a parent-child relationship to organize files. Refer to Figure 4-4 for an explanation on tree structure.
32 Hierarchy: A way of classifying data, starting with the general and going to specific. Cabinet Files organized into different locations based on their category Infosys Limited Operating Systems
Version 1.0 71
Figure 4-4: Example for a tree data structure
Top of the directory is known as a root directory which holds numerous files and sub- directories. In this example C: is the root directory and it has numerous files and sub- directories. The sub-directories shown are CHSSC and PF. Each of these sub-directories further has sub-directories called course material.
4.2. File Organization in MS-DOS This sub-section deals with the organization of files in the hard disk in an MS-DOS OS. The OS allocates disk space based on the demand made by the user programs.
coursematerial CHSSC C: PF coursematerial Infosys Limited Operating Systems
Version 1.0 72
Figure 4-5: Structure of a Hard Disk
Refer to Figure 4-5 for the discussion of the structure of a hard disk. The hard disk is normally made up of multiple disk Platters 33 . Disk platters are similar to a collection of compact disks piled on top of each other. In Figure 4-5 the hard disk is made up of three platters. The disk platter is divided into circular recording units called tracks. The Figure 4-5 shows one such track for each of the disk platters. The track is in turn subdivided into sectors. A sector can be considered to be the basic data storage unit in a hard disk. A number of sectors make a track and a number of tracks make a disk platter. The set of tracks across platters which have the same radius form a cylinder. So the hierarchy in terms of disk structure is that a number of sectors make up a track and a number of tracks make up a cylinder.
The size of each sector is 512 bytes. In MS-DOS file system the disk space is normally allocated in units of a fixed size called a cluster. A cluster is a collection of sectors. In other words a cluster is a multiple of the sector size. Typical sizes of a cluster are 512, 1024 and 2048 bytes. So any new file that is created will have a minimum space assigned to it which is nothing but one cluster. As more and more data is added to this file, it gets appended to the cluster and based on the further demand additional clusters are allocated for this file.
33 Platter: A metal disk covered with magnetic recording material. SECTOR CYLINDER TRACK PLATTER Infosys Limited Operating Systems
Version 1.0 73 The clusters could be considered to be synonymous with the paging technique which was discussed in memory management. Since there are multiple files in the system which could be accessed at any given point of time, the clusters allocated for these files may not sit in contiguous locations in the hard disk. This is exactly similar to the paging technique where in the pages need not sit in contiguous memory locations. The following scenario would help in better understanding of this concept.
Consider a situation where in a user creates a file, say file A and puts some data into it (refer to Figure 4-6).
Figure 4-6: Example for allocation for clusters
Three clusters (cluster 1, cluster 2, and cluster 3) are allocated to file A. Now this file is closed and another file, say file B is created and some data is put to this file. Two clusters (cluster 4 and cluster 5) are allocated to file B. Again when file A is opened to append some data a new cluster (cluster 6) is allocated to file A. This new cluster is not contiguous to the earlier clusters of file A.
The next immediate question is how does MS-DOS OS know the location of all the clusters allocated to a file? 4.3. Data Access in MS-DOS To identify all the clusters of a particular file MS-DOS uses a mechanism where the next cluster number in the sequence is stored in a table. This table is called the File Allocation Table (FAT).
The FAT is similar to a table of contents that gives information about the clusters allocated to every file in the disk. Refer to Figure 4-7 for the discussion on FAT.
Cluster 1 Cluster 2 Cluster 3 Cluster 4 Cluster 5 Cluster 6 File A File A File B Infosys Limited Operating Systems
Version 1.0 74
Figure 4-7: File Allocation Table (FAT)
The FAT is an array 34 of 16 bit entries. The array index starts from 0. The entries in the array (FAT) correspond to the cluster numbers of a file except for the first two entries of the FAT. The first entry of the FAT which is FFFD identifies the disk type and the second entry which is FFFF indicates a value which signifies the last cluster of a file.
The first cluster of file A is cluster 2. The FAT entry for index 2 is 0003 which indicates that the next cluster of file A is cluster 3. Similarly the FAT entry of index 3 is 0004 which means cluster 4 is the next cluster. Following cluster 4 is cluster 7 in the sequence and from the FAT entry for index 7, which is FFFF, it is seen that cluster 7 is the last cluster of file A.
Similarly the sequence of clusters for file B is cluster 5 followed by cluster 6. Also a value of 0000 in the FAT indicates that a particular cluster is free. In the Figure 4-7 cluster 8 is a free cluster.
34 Array: A data structure which stores same kind of data in contiguous memory. FFFD FFFF 0003 0004 0007 0006 FFFF 0 1 2 3 4 5 6 FFFF 0000 8 7 First Cluster of File A First Cluster of File B End of File A is cluster 7 End of File B is cluster 6 Cluster 8 is free Infosys Limited Operating Systems
Version 1.0 75 The FAT mechanism is also known as system of chained pointers 35 as each entry in the FAT points to the next cluster number for a particular file there by forming a chain of pointers.
But from where did the OS get the information that the first cluster of file A is cluster 2 and the first cluster of file B is cluster 5?
As mentioned earlier, every file in MS-DOS is part of a directory. For every directory in the disk a directory table is maintained by MS-DOS which gives details about every file in that directory. These details include file name, size of the file, type of file, first cluster of the file etc. The OS gets the information of the first cluster of a file from this directory table. An example of directory entries for two files, namely file A and file B, is shown in Figure 4-8.
Figure 4-8: Directory Entries for files
The directory table entry for File A gives the details of the first cluster, which is cluster 2. Now the OS uses this information to navigate through the FAT to find out the remaining clusters for file A. Similarly the directory table entry for File B gives the details of the first cluster for File B which is cluster number 5.
Example1: Find the number of FAT entries required for the following specification. disk capacity = 32MB size of the sector = 512 Bytes Number of sectors per cluster = 4 Solution: Size of each cluster is 4 * 512 = 2048 bytes Disk capacity in bytes = 32 * 2 20 Bytes Number of possible clusters for the given disk capacity is 32 *2 20 / 2048 =16*2 10
As FAT entries denote the cluster numbers, the number of FAT entries required is 16k
35 Pointer: A variable which points to the address of a data in memory. File A txt 119 Bytes 2 File B txt 27 Bytes 5 Infosys Limited Operating Systems
Version 1.0 76 4.4. Volume Structure of the Disk in MS-DOS The term volume refers to the storage area in the secondary storage. A hard disk can have multiple volumes. The following example would help in better understanding the term volume.
Figure 4-9: Example to illustrate the term volume
The cassette in Figure 4-9 is a recording medium. The two sides of the cassette, namely side A and side B, which are used for recording is synonymous to the volume in a hard disk. A hard disk can be partitioned into multiple volumes.
The volume structure of a disk defines the way in which disk is organized. In MS-DOS OS the volume structure of the disk has the following (refer to Figure 4-10):
Figure 4-10: Volume structure of a disk in MS-DOS 1. Boot Sector: The boot sector contains all information about the disk characteristics. Some of these disk characteristics are the disk manufacturers name, version and the allocation details like the number of tracks per cluster and the number of FATs 36 . The boot sector also contains an important program called the bootstrap loader. The bootstrap loader is the one of the first program which gets executed when the computer is switched on and the bootstrap loader loads the OS from the disk to the main memory
36 FATs: In MS-DOS OS a number of copies of the FAT are maintained so that it can be used if the main FAT gets corrupted. S I D E A Cassette Boot Sector FAT Additional FATs Root Directory File Space Volume Structure of a Disk Infosys Limited Operating Systems
Version 1.0 77
2. FAT: The file allocation table is part of the volume structure of the disk
3. Additional FAT(s): Duplicate copies of the FAT are stored in the disk which gets updated along with the main FAT. The duplicate copies are used if the main FAT gets corrupted
4. Root Directory: It is a special kind of directory which has a fixed position in the disk and also the size of the root is fixed. The OS programs normally reside in the root directory
5. File Space: Relates to rest of the disk which is used for files and sub-directories.
The volume structure of a disk in MS-DOS can be compared with the structure of a book. The first few pages of the book, which has the publishers name, edition number, catalog number and preface is synonymous with the boot sector. The table of contents in the book is synonymous with the FAT. The structure of the book does not have any direct analog to additional FATs. The overview which follows the table of contents is synonymous with the root directory. The position of the overview in the book is fixed and also normally the overview runs only for a few pages. The actual contents of the book is synonymous to the file space where in various files are stored.
4.5. MS-DOS Booting Process Whenever the computer is switched on (refer to Figure 4-11), a piece of program called BIOS 37
performs a test to check if the hardware components are functioning properly. This test is called Power On Self Test (POST). After performing the POST the BIOS starts performing the booting 38 process by reading through the boot sector in the hard disk and loading the bootstrap loader into the main memory and executing it. The bootstrap loader now locates the MS-DOS operating system files (MS-DOS.SYS and IO.SYS 39 ) in the root directory and loads them into main memory and executes them which in turn make the operating system functional.
37 BIOS: Basic Input and Output System (BIOS) is a piece of software that is hardwired into the ROM. 38 Booting: Starting up of the computer when it is switched on. 39 MS-DOS.SYS and IO.SYS: These are the operating system files which govern the OS services. Infosys Limited Operating Systems
Version 1.0 78
Figure 4-11: MS-DOS Booting Process
4.6. UNIX File System In UNIX OS the Hard Disk can be divided into multiple file systems. Recall that a file system is the structure in which files are organized. Analogous to clusters in MS-DOS, UNIX allocates disk space in terms of blocks. The block size is a multiple of 512 bytes. A file system in UNIX consists of a sequence of logical blocks. There is one compulsory file system in UNIX which is called the Root File system. The remaining file systems are optional and are left to the choice of the Administrator 40 .
The file system in UNIX is different to that of MS-DOS. UNIX file system is hierarchical. At the top of the hierarchy is the root file system (refer to Figure 4-12) which acts as parent to the remaining three file systems, namely File System 2, File System 3 and File System 4.
40 Administrator: One who maintains the computer system. BIOS Bootstrap Loader OS Files (MS-DOS.SYS and IO.SYS) MS-DOS Operating System Power On Self Test Infosys Limited Operating Systems
Version 1.0 79
Figure 4-12: UNIX File System Hierarchy
4.7. File Organization in UNIX The disk storage in UNIX can be viewed as one which has three components, namely:
x Directory Entry Table: Every directory in UNIX has a directory entry table which has the following information for every file in that directory. Name of the file and A pointer to a block which contains the detailed information about the file. This block is called the inode block
x Inode Block: A data structure called inode (index node) block is used for describing every file in UNIX. This inode block contains information about the file. Every file in UNIX has an inode block associated to it. This inode block is identified by a unique number called the inode number which is associated to every file. The following are some of the important information which the inode block contains for every file:
The type of the file (could be a regular file or a directory or a device like floppy disk) Owner of the file (person who has created the file) Location of the file Size of the file Last modified time of the file Last accessed time of the file A set of pointers to a block which contains the actual data of that file. This block is called the data block
x Data blocks: The data blocks are the one which contains the actual data. These data blocks are allocated by UNIX whenever some data is written to a file.
An example of the disk storage for two files (File 1 and File 2) is shown in Figure 4-13. root File System 4 File System 2 File System 3 Infosys Limited Operating Systems
Version 1.0 80
Figure 4-13: Disk Storage in UNIX
How is the actual data accessed from the inode block? 4.8. Data Access in UNIX The inode block for every file has an array of thirteen pointers. But what do they point to? Refer to Figure 4-14 for the discussion on accessing data from the inode block.
Data Block Details about File 1 y type of file y ... y size of file y y pointers to data block Details about File 2 y type of file y ... y size of file y y pointers to data block Data Block Data Block File 1 File 2 Data Block Data Block Directory Entry Table Inode block for file 1 Inode block for file 2 Infosys Limited Operating Systems
Version 1.0 81
Figure 4-14: Inode pointer structure
Assume that the size of a block is 512 bytes and the size of a pointer is 4 bytes.
The first 10 elements of the array of pointers are called direct pointers. These elements point to the address of a data block in the hard disk. Whenever a file is created a data block is allocated to the file to store the data and also the address of this data block is stored in the first position of the array, i.e. the first direct pointer (direct 0 in Figure 4-14) has the address of the first data block that was allocated. As and when the size of a file increases the OS Data Block Data Block Data Block Index Block Index Block Index Block Index Block Index Block Index Block Direct 0 Direct 1 Direct 9 Single Indirect Double Indirect Triple Indirect . . . Data Block Data Block Data Block Array of 13 pointers Infosys Limited Operating Systems
Version 1.0 82 allocates data blocks to it and stores the address of these data blocks in the remaining direct pointers in the inode block. So, if ten data blocks are allocated to a file then the address of these data blocks will be stored in the ten direct pointers (direct 0 to direct 9 in Figure 4-14) of the inode block of this file. This would mean that the size of the file is 512 * 10 = 5120 bytes. Then what do the remaining three pointers (single indirect, double indirect and triple indirect in Figure 4-14) in the inode block signify? Before answering this question first consider the following.
Consider a case where in the file would grow in size on a regular basis; say a file which contains employee information of a company which would increase in size as and when more employee join the company. If all the thirteen elements of the array of pointers were to directly point to the data blocks then the maximum size of a file that could be addressed using the inode block would be 512 * 13 = 6656 bytes. If the file increases beyond this size then there would be a need for more elements in the array of pointers in the inode block (say 14 th pointer, 15 th pointer and so on). This would require the size of the array of pointers to increase dynamically. Instead UNIX uses a different approach.
When the size of the file grows beyond 5120 bytes, then the UNIX OS uses the 11 th pointer, called the single indirect pointer (refer to Figure 4-14), to get the address of the data blocks. This single indirect pointer does not directly point to a data block, instead it points to a block called index block which is 512 bytes of size. This index block is an array of pointers. Since each pointer occupies 4 bytes, the number of such pointers possible for the index block is total size divided by the size of one pointer which is 512/4 = 128. So the index block is divided into an array of 128 pointers. Each of these 128 pointers points to a data block of 512 bytes. In this way the maximum size of the file that could be addressed using single indirect pointer would be 128 * 512 = 65536 bytes. Hence the total file size that could be addressed using all the ten direct pointers and the single indirect pointer is 5120 + 65536 = 70656 bytes. This is equivalent to 138 data blocks.
Now if the size of the file grows beyond 70656 bytes then UNIX uses the 12 th pointer, called the double indirect pointer (refer to Figure 4-14), to get the address of the data blocks. The double indirect pointer points to an index block of 512 bytes of size. This index block is again an array of 128 pointers. Each of these 128 pointers again point to an index block of 128 pointers which in turn point to the data blocks. In this way the maximum size of the file that could be addressed using double indirect pointer would be 128 * 128 * 512 = 8388608 bytes. Hence the total file size that could be addressed using all the ten direct pointers, the single indirect pointer and the double indirect pointer is 70656 + 8388608 = 8459264 bytes. This is equivalent to 16522 data blocks.
If the size of the file grows beyond 8459264 bytes then UNIX uses the 13 th pointer, called the triple indirect pointer (refer to Figure 4-14), to get the address of the data blocks. The triple indirect pointer points to an index block of 128 pointers each of which points to another index block of 128 pointers. Each of the 128 pointers in the second index block again point to an Infosys Limited Operating Systems
Version 1.0 83 index block of 128 pointers each of which in turn points to a data block. So the maximum size of the file that could be addressed using the triple indirect pointer would be 128 * 128 * 128 * 512 = 1073741824 bytes. Hence the total file size that could be addressed using all the ten direct pointers, the single indirect pointer, the double indirect pointer and the triple indirect pointer is 8459264 + 1073741824 = 1082201088 bytes. This is equivalent to 2113674 data blocks. If the size of the file grows beyond this size then UNIX has a provision to include the fourth indirect pointer and so on. 4.9. Volume Structure of the disk in UNIX The volume structure of UNIX is different from that of MS-DOS. Recall that UNIX allows multiple file systems to exists in the same hard disk. Every file system in UNIX has the following layout (refer to Figure 4-15).
Figure 4-15: Volume Structure of UNIX File System
x Boot Block: The boot block contains the boot strap loader which is copied into the main memory when the computer is powered on. The boot strap loader is the first program which gets executed when the computer is switched on, which in turn loads the UNIX OS into main memory. The boot block is analogous to the boot sector in MS- DOS. The Figure 4-15 shows three file systems as part of a disk in UNIX and all the three have the boot block. Why is there a need to have boot block in every file system when only one boot strap loader program is required for the computer to boot? This is maintained just for sake of consistency among all file systems. Only the root file system, which is a compulsory file system in UNIX, has the boot strap loader in its boot block. The boot block in the remaining file systems would be empty
Boot Block Super Block Inode Block Data Block File System 1 Boot Block Super Block Inode Block Data Block File System 2 Boot Block Super Block Inode Block Data Block File System 3 Infosys Limited Operating Systems
Version 1.0 84 x Super Block: The super block has the complete summary of the file system. It describes the state of the file system by maintaining the following information
Size of the file system List of free inode blocks List of free data blocks Size of the disk block
x Inode Block: The Inode block follows the super block and it has a unique record 41 , the inode, for every file in the file system. The inode gives the all the information about the file and the disk layout of the file. The inode for every file is identified and accessed by a number called the inode number. Some of the important information which the inode maintains has already been discussed.
x Data Block: The data block contains only data. The information about which data block corresponds to which file is maintained in the inode block.
4.10. File Permissions DOS is not a multi-user system. The security in terms of file permissions is very limited in nature.
On a system with many users sharing the files, it is very important to keep a few files private. UNIX is a multi-user, multitasking, multiprocessing operating system. In UNIX every user has a username and belongs to one group. For example, user name could be Venkat belonging to group called aug05. There could be other users in the same group. As well there could be many other groups of similar kind.
The files belonging to user Venkat could be allowed to be accessed by other group members or even the members of other groups, if the owner (Venkat) is willing to do so.
A file could be accessible for read (r), write (w) or execute(x). In execute mode the executable files can be executed.
The read, write and execute permission could be given to a file in such a way that only the owner can use them accordingly, or permissions could be given to the entire group(g) or members of other groups(others o).
Consider a case where the owner of the file wants to give read write and execute permission the all members in the group and the others as well then the permission set will be as shown in Figure 4-16 (a). Similarly the situation where in the owner wants to keep all the access
41 Record: collection of related information. Infosys Limited Operating Systems
Version 1.0 85 permissions to himself but restrict the group and others to read only is shown in Figure 4-16 (b) . Figure 4-16 (c) shows a situation where in all kinds of access permissions are given to owner but read and write to group and no access permissions of any kind is given to the others.
Figure 4-16: UNIX file permissions
File permission could also be represented in terms of numbers as well. Read is given a value of 4, write is equal to 2 and execute is equal to 1. So in the case of Figure 4-16(a) where in the users file has rwx (=4+2+1=7) permission for owner, group and others, we can represent the permission for this file as 7 7 7. Similarly the file permission for the case in Figure 4-16(b) is 7 4 4 . For the case in Figure 4-16(c) it is 7 6 0. 4.11. New Technology File System (NTFS)
NTFS is a file system used by Windows NT and its descendants (Windows 2000 and Windows- XP). This is completely different from FAT file system used in MS-DOS and early versions of Windows.
r x w r x w r x w Owner(u) Others(o) Group(g) r x w r - - r - - Owner(u) Others(o) Group(g) r x w - - - r - w Owner(u) Others(o) Group(g) a) Owner, group and others all have read, write and execute permissions b) Owner has read, write and execute permissions, while Group and others have only read permission c) Owner has read, write and execute permissions, while Group has read and write and others don't have any permission Infosys Limited Operating Systems
Version 1.0 86 NTFS has several improvements over the FAT like improved support to store the information of the files and the data structures so as to improve performance, reliability, security and optimal disk space utilization.
4.12. Features of the NTFS file system
Security and access control: Like in UNIX, this file system implements built in facility for controlling access to the files and folders in the hard disk. This is a very important feature which was not so inherently built in FAT based file systems.
Size of the files/ The number of files: NTFS supports large files and virtually any number of files in the hard disk. Unlike in FAT the performance does not degrade with large volume of data access. In FAT file system the FATs would occupy a large amount of disk space themselves. The NTFS uses a different approach to allocate space to the files, thus using disk space efficiently. s Recovery/Reliability: NTFS implements features to recover from problems without any loss of data. In the event of a system crash, the file system design prevents corruption of data.
Long file names: NTFS allows file names to be of 255 characters in length. In FAT the limitation was 8 characters for filenames and 3 for extension names (Example: myfile.doc).
4.13. Overview of the partition Structure:
NTFS divides disk space into clusters as in case of the FAT file system. NTFS supports almost all sizes of clusters from 512 Bytes to 64 Kbytes. But 4Kbytes is considered to be the standard one.
The NTFS is logically divided into two parts as shown in Figure 4-17.
Figure 4-17: NTFS partition structure
MFT USER FILE SPACE USER FILE SPACE Copy of first 16 MFT records Infosys Limited Operating Systems
Version 1.0 87 The first part in the partition structure is called the Meta File table or MFT. This holds the information about the other files called the metadata 42 or the metafiles. The other part of this structure is used for the actual user data files.
The MFT contains entries that describe all system files, user files and directories. Each MFT entry is given a number (similar to inode numbers in UNIX). The first sixteen entries in MFT correspond to the system files including #0 which describes the MFT itself. The user files and directories start at #25.
A copy of the first sixteen MFT entries is duplicated exactly at the middle of the User file space. The detailed discussion on the NTFS is beyond the scope of the discussion and is also the proprietary format of Microsoft.
4.14. Limitations of NTFS
1. The file encryption is not inbuilt in NTFS and hence one can boot through the MS-DOS or any other Operating System and use low level disk editing utility to view data stored on a NTFS volume. NTFS5 the enhanced version of NTFS addresses this issue. 2. For disk volumes of less than 400MB, the overhead becomes too large. 3. Formatting floppy disks is not possible in NTFS.
The following table compares the different file systems discussed.
Features FAT NTFS UNIX file System Operating Systems DOS and all versions of Windows Windows NT, Windows 2000, Windows XP UNIX and Unix based OS like Linux, etc. Volume size Limited Virtually unlimited Virtually unlimited Max file size Limited Limited by the volume of the disk Limited by the volume of the disk Number of files Limited Large Large Built-in security No Yes Yes Encryption NO Supported in the recent versions like NTFS5. Inherent Fault tolerance Low High High Table 7 : Comparison of File systems
42 Metadata: Data about the data. Typical example could be the catalog card in the library, which contains information about the book and its location. Infosys Limited Operating Systems
Version 1.0 88 5. Device Management A computer system has a wide range of peripheral devices which are also called the input/output (I/O) devices. These include keyboard, mouse, monitor, printer etc. These devices are the means by which the computer system interacts with the user. The amount of data which these devices can process per unit of time is less compared to the CPU because of their mechanical nature of operation. Hence these I/O devices can become a bottleneck if they are not managed well. The part of the OS which manages these devices, so as to allocate them to a particular users job, is called the device manager. 5.1. I/O Channels, Interrupts and Interrupt Handling
Recall that a data bus is used to transfer data from one part of the computer to another. In order to overcome the disparity in speed of the operations between the I/O devices and the CPU a separate channel is maintained for the communication between the I/O devices and the computer. This channel is called the I/O bus system or the I/O channel.
Whenever a currently executing process requires an I/O, the process context has to be saved and the process has to move to the blocked state and wait for the completion of the I/O. But how does this happen?
The initiation and the completion of an I/O request between the CPU and the I/O channel is done by means of an interrupt. An interrupt is a hardware facility which causes the CPU to suspend its work, save the context of the currently executing process and send appropriate request to the I/O devices. The CPU oversees the data transfer and sets appropriate status bit 43 as and when required. Once the I/O device has completed servicing this request it sends an interrupt back to the CPU so as to enable the CPU to assign further requests to this device. The act of causing the CPU to suspend its work, save the context of the currently executing process and send appropriate request to the I/O device is called the interrupt handling routine. There are different kinds of interrupts like the peripheral interrupt, error interrupt etc which are classified based on their priority. A peripheral interrupt has the highest priority when compared to the other hardware interrupts.
After a CPU initiates an I/O request is it really necessary for the CPU to get involved in the data transfer during an I/O operation? The following section addresses this question and by introducing a technique which would speed up the data transfer rates by the peripheral devices.
43 Status Bit: A 0 or 1 value used to indicate the current status of an operation. Infosys Limited Operating Systems
Version 1.0 89
Note: If the interrupt occurs in the middle of the execution an instruction the CPU completes that particular instruction and then and only then services that particular interrupt.
5.2. Direct Memory Access Direct Memory Access (DMA) is a technique which is used to transfer data between the memory and the I/O devices with the least amount of effort by the CPU. Once the CPU initiates an I/O request, the data transfer between the memory and the I/O device is done directly without the involvement of the CPU. Thus the name of the technique - Direct Memory Access. Once the data transfer is complete the CPU is notified by means of an interrupt. For DMA a hardware device called DMA controller, which is a special purpose processor, is used which ensures the completion of the I/O request. All the status bits are set by this DMA controller. A DMA controller has access to the data bus of the computer system and as a result it can transfer the data in and out of the memory.
Whenever a data transfer is required by a program the DMA controller would notify the CPU. The CPU would release its control over the data bus and as a result the DMA controller would access the memory directly without the intervention of the CPU and do the data transfer. This mechanism of stealing the data bus from the CPU and using it for the data transfer between the memory and the I/O devices is called cycle stealing. During this time the CPU cannot access the main memory but it can access its cache memory and it can perform its activity without having to wait for the completion of the I/O request. Most of the peripheral devices like the floppy disk, hard disk etc., use the DMA technique. 5.3. Software Interrupts Software interrupts are programmed interrupts. Recall that hardware interrupts are a special kind of device which provides the interrupt facility. Operating systems provide the facility wherein programs (software) can act as an interrupt. In what scenarios would these software interrupts used?
Consider an application program that is being executed by a user. Whenever the application program requires a service from the OS like reading data from the disk, a software interrupt also called as trap is generated which will save the current state of the application program and invoke the file manager of the OS to provide the appropriate service. Once the data is read into memory the software interrupt restores back the current state of the application program so that it could continue from where it was interrupted. The control - C key which is normally used to send some kind of interrupt signal is also a software interrupt. Infosys Limited Operating Systems
Version 1.0 90 5.4. Structure of an I/O System The typical structure of an I/O system is shown in Figure 5-1.
Figure 5-1: Structure of an I/O System
When ever an application program requires any kind of I/O it sends a request to the I/O control system (IOCS). The I/O control system is a set of programs which is part of the operating system. The tasks of the I/O control system is to accept I/O request from application programs, do the initial processing, validation of requests and to route 44 the request to the appropriate device. The application requests are conveyed to the IOCS by means of software interrupts. The IOCS in turn sends these requests to device drivers which are software modules whose task is to convert the application program request, also called the logical request, into commands that the device can understand. In most of the cases each device has a separate device driver. The device driver sends these device specific requests to the device controller through the I/O bus.
Device controllers are hardware devices which control the devices. The device controller gets this request serviced by the hardware and routes the I/O response back to application program through the device driver and the I/O control system. 5.5. Types of Device Allocation Is it possible to use the same scheduling algorithms, discussed in process management, for allocation of devices?
Consider the following scenario where in a round robin scheduling algorithm is used for allocation of a printer. Two users A and B want to print files on this printer. Initially user A sends a print request for a 100 page document. Immediately following this user B sends a print request for a 20 page document. Since the printer allocation is done using round robin scheduling, the printer would first start the 100 page document and after the elapse of the time slice, say by when 30 pages are printed, the printer would start printing the 20 page document of user B. This way the print out of both the documents would be jumbled up. First 30 pages of user As document, followed by 20 pages of user Bs document and following
44 Route: Send to destination. Application Program Input - Output Control System Device Driver Device Controller Hardware Device Software Interrupts I/O Bus Operating System Infosys Limited Operating Systems
Version 1.0 91 which the remaining pages of user As document. This is definitely not desirable. The scheduling algorithms discussed in process management cannot be applied for device allocation.
The following are the two types of device allocation policy that are used.
Dedicated: Some of the devices, like the printer, can be used in a serial fashion one at a time. So if a user A sends a print request for a huge file of 1000 lines then the other print jobs 45 should wait for this print request to be serviced before they can issue a request. This is one major disadvantage of dedicated allocation policy as it could lead to a monopoly of one huge print request.
To overcome this drawback most operating systems use a technique called Simultaneous Peripheral Operations Online (SPOOLing) where in the all the print jobs are saved in the disk until the print job is completed. All the saved print jobs would be printed in the order in which they were saved. Whenever simultaneous operations are made on these peripheral devices, like the printer, the requests are put in a print queue. This queue is stored as file in the hard disk and is called the spool file. Whenever the resource is free the contents of the spool file are retrieved and the print requests are serviced (refer to Figure 5-2).
Figure 5-2: Example of a Spool File Why is there a need to store the print jobs in a file in the disk? The printing does not get interrupted even if the user closes the document that he has given for printing. This is possible because the printing takes place from the local copy in the disk namely the spool file.
Shared: There are certain devices which can be used concurrently by many users. Such devices are said to be shared across users. One example of a device which uses the shared allocation policy is the hard disk.
The concurrent access of a device, due to the shared allocation policy, can lead to multiple jobs trying to write (or read) data from the same file at a given point of time. The shared
45 Print Jobs: Jobs which are waiting to be printed. Infosys Limited Operating Systems
Version 1.0 92 allocation policy for the device management in any operating system should bring in a mechanism to protect the data of a file from such concurrent access.
5.6. Disk Scheduling One of the goals of operating system is to use hardware efficiently. Disk drive efficiency is based on two factors namely fast access time and disk bandwidth. Access time has two major components x Seek time is the time required to place the read/write head to the cylinder containing the desired sector x Rotational latency is the time required for the disk to rotate the desired sector under the disk head Disk bandwidth is the total number of bytes transferred, divided by, the total time between the first request for service and the completion of the last transfer. Typical structure of a Disk is shown in Figure 5-3.
Figure 5-3: Structure of a Disk
Access time and Disk bandwidth can be improved by scheduling efficiently the servicing of disk I/O requests maintained in disk queue. Accordingly, there are several disk scheduling algorithms as follows.
Cylinder Track Latency Seek R/W Infosys Limited Operating Systems
Version 1.0 93 FCFS Scheduling: In the First Come First Served scheduling, operations are performed in the same order as in the disk queue. Limitation of this algorithm is the poor performance. However, there will be no starvation as every request is served in first cum first serve basis. Example: Consider a total number of 200 cylinders (0 to 199). Initially consider that the disk head is at cylinder number 100. Then for the requests in the Disk Queue in the order (30, 85, 130, 45, 175), the total seek time is estimated by total arm motion as |100-30| + |30-85| + |85-130| + |130-45| + |45-175| = 70+55+45+85+130 = 385
SSTF Scheduling: In the Shortest Seek Time First scheduling, the request having minimum distance/seek time from the current head position is serviced first. After servicing a request, nearest request in the disk queue is serviced, without considering the direction. Compared to FCFS, this algorithm reduces total seek time. However, starvation is possible and change in direction slows down the operation. Example: Consider a total number of 200 cylinders (0 to 199). Initially consider that the disk head is at cylinder number 100. Then for the requests in the Disk Queue in the order (30, 90, 115, 45, 130,175), the total seek time is estimated by total arm motion as |100-90|+ |90- 115| + |115-130| + |130-175| + |175-45| + |45-30| = 10+25+15+45+130+15 = 240
SCAN Scheduling: This is also called as Elevator algorithm. In this algorithm, the disk arm starts at one end and moves towards the other end of the disk, servicing requests until it gets to the other end of the disk. At other end, the head movement is reversed and servicing continues. In this algorithm variances are less as compared to SSTF. Example: Consider a total number of 200 cylinders (0 to 199). Initially consider that the disk head is at cylinder number 100. Then for the requests in the Disk Queue in the order (30, 85, 130, 45, 175), the total seek time is estimated by total arm motion as |100-85| + |85-45| + |45-30| + |30-0| + |0-130| + |130-175|= 15+40+15+30+130+45 = 275
C-SCAN Scheduling: In the circular scan algorithm, the disk head moves from one end to the other end of the disk and provides services to requests as it moves, servicing requests in one direction only to provide uniform wait. When disk head reaches to the other end, it returns immediately to the start of the disk. It does not serve requests during the return trip. Example: Consider a total number of 200 cylinders (0 to 199). Initially consider that the disk head is at cylinder number 100. Then for the requests in the Disk Queue in the order (30, 85, 130, 45, 175), the total seek time is estimated by total arm motion as |100-85| + |85-45| + |45-30| + |30-0| + |0-199| + |199-175| + |175-130| = 15+40+15+30+199+24+45 = 368
LOOK Scheduling: This algorithm is similar to SCAN scheduling but disk head stops moving towards end when there is no more requests in that direction. Disk arm moves only up to the last request in each direction. This algorithm provides services in both directions. Example: Consider a total number of 200 cylinders (0 to 199). Initially consider that the disk head is at cylinder number 100. Then for the requests in the Disk Queue in the order (30, 85, 130, 45, 175), the total seek time is estimated by total arm motion as |100-85| + |85-45| + |45-30| + |30-130| + |130-175| = 15+40+15+100+45 = 215 Infosys Limited Operating Systems
Version 1.0 94
6. Summary In this Chapter, the following were discussed: x The need for memory management x The different types of memory management with their advantages and disadvantages o Single Contiguous Memory Allocation o Fixed Partition Memory Allocation o Variable Partition Memory Allocation o Re-locatable Partition Memory Allocation o Simple Paged Allocation o Virtual Memory and Demand Paging o The various page replacement algorithms were discussed o Simple Segmentation x Process Management o The structure of a process and its states with various possible state transitions were examined. o Need for multiple processes and types of multiple processes were introduced and mechanisms for inter process communication were looked at o Multiprogramming, Multiprocessing and Multitasking were introduced and their differences were understood o Types of Multitasking were examined o Need for threads and advantages of multithreading were described o Different kinds of scheduling were introduced and their advantages/disadvantages were examined o Shortest Job First o Round Robin o Priority Scheduling x File System Management o The File System of MS-DOS OS was studied File Organization and Data Access in MS-DOS was examined MS-DOS booting sequence was introduced o The UNIX File System was introduced File organization and data access in UNIX was examined o NTFS was discussed x Device Management o The need for managing devices was introduced and different kinds of device management were examined I/O channels and Interrupt Handling were introduced The need for DMA was introduced Structure of an I/O System Different types of device allocation were studied Infosys Limited Operating Systems
Version 1.0 95 7. Exercises
1. Discuss briefly the different types of memory allocations possible. Also explain the pro and cons of each of these.
2. What is virtual memory? Explain clearly how it benefits the memory management.
3. Discuss the need for page replacement and the different types of page replacements.
4. Explain the difference between segmentation and paging
5. What do we mean by a process? Explain with state transition diagram the different states that the process could be in.
6. Explain Multiprogramming, Multitasking, Multiprocessing and Multithreading.
7. Compare and contrast the File system organization in DOS and in UNIX.
8. Explain clearly the concept of DMA.
Infosys Technologies Limited Glossary
Version 1.0 96 Glossary Address: corresponds to the location of any information (program or Data) in the memory
Administrator: One who maintains the computer system
Algorithm: A sequence of instructions to perform a particular task. It is does not have any syntax and is written as English statements
Array: A data structure which stores same kind of data in contiguous memory
Automated Teller Machine (ATM): An automated machine which allows customers to perform banking transactions anytime. It is primarily used for dispensing cash
BIOS: Basic Input and Output System (BIOS) is a piece of software that is hardwired into the ROM Book keeping: All additional information which are maintained to describe the task and the resources which it consumes like CPU time, memory, etc.
Book keeping: All additional information which are maintained to describe the task and the resources which it consumes like CPU time, memory, etc.
Boolean: The term Boolean corresponds to the Binary True or False
Boolean operations: Operation that results in True or False
Booting: Starting up of the computer when it is switched on
Bottleneck: Situation that hinders progress due to blockage
Buffer: Temporary memory location usually used to store data to be transferred to another location.
Bus Width: corresponds to the number of bits that could be accommodated at once
Byte: Byte corresponds to 8 bits. A bit is one Binary digit
Cache: Storage location
Circular queue: A type of queue where in the last element in the queue is connected back to first element of the queue
Coalescence: Merging
Comments: The comments are written by the programmer for the understanding of the code written by him (For Documentation purpose)
Concurrently: Parallel
Co-processor: Co-processors are used along with the normal processors (CPUs) to assist the CPU in doing certain operations, in this case Floating Point Operations.
Data Structure: Scheme for grouping related data
Decoded: Interpreted
Infosys Technologies Limited Glossary
Version 1.0 97 Display Monitor: A device which is used to display pictures and text
Editor: A program which helps in editing programs and documents. Microsoft word is an example of an editor
Endian: A term describing different ways of ordering bytes in storage
FAT: In MS-DOS OS a number of copies of the FAT are maintained so that it can be used if the main FAT gets corrupted
File System: The structure by which files are organized, named and stored in an OS
Floating Point: This corresponds to the real values with exponentiation. Example: 123.34 * 104 can be written as 1.2334 * 102. The decimal point changes its location (Floating)
Global Data: Variables which are accessing throughout the entire program
Key Board: A device which is used to type text or instructions to the computer
KiloByte: It is a unit of measure for data storage. 1 Kilobyte(KB) = 1024 bytes
Logical Drive: The internal division of a large hard disk into smaller units. Normally one single physical drive is divided into several logical drives
MB: MB or Mega Bytes. 1 MB= 2 20 Bytes
Memory Unit: Storage devices used to store the information
MHz: Mega Hertz; Mega = 10 6 ; Hertz is the unit of frequency
Mnemonics: visual or word related aids that facilitate retrieval of information
Monopoly: controlled by one party
MS-DOS.SYS and IO.SYS: These are the operating system files which govern the OS services
Multiprogramming: The act of having multiple programs in memory ready for execution is called multiprogramming
Overhead: operating expense
Platter: A metal disk covered with magnetic recording material
Portable: One which can be carried from one place to another
Preemption: Taking possession of CPU before the currently running process relinquishes the same
Primitive: Basic
Print Jobs: Jobs which are waiting to be printed
Priority: Importance
Infosys Technologies Limited Glossary
Version 1.0 98 Procedures: A set of instructions to accomplish a specific task
Process: A process is also known as an instance of a program in execution. Multiple instances of the same program can execute simultaneously, for example the mail program.
Programmer: One who writes programs is called as the programmer
Record: collection of related information
Semantic: Meaning
Single threading: Allowing only one thread per process
Status Bit: A 0 or 1 value used to indicate the current status of an operation
Symbol Tables: A table where symbol names and associated data are stored. This helps the usage of existing information in repeated uses of those symbols.
Telnet: A protocol which helps to connect to a remote computer in the network
Time Slice: A quick period of time in which a process is given to access the CPU
Uniprocessor System: Computer Systems which have a single processor
Uniprogramming: Ability of the OS to allow only one process to reside in memory
User Jobs: All programs, except the OS, which are loaded into main memory for execution
Virtual: Something that is not real
Volatile Memory: The term volatile memory corresponds to the fact that the information present in these types of memory devices is lost as soon as the power is turned off Infosys Technologies Limited Index
Version 1.0 99
Index
B Boot Block .......................................... 85 Boot Sector ......................................... 78 C Code Region ........................................ 36 Compaction ........................................... 9 Context Switching ................................. 41 Cooperating Process .............................. 43 Cooperative Multitasking ......................... 47 D Data Blocks ......................................... 81 Data Region ......................................... 36 Demand Paging..................................... 19 Direct Memory Access ............................ 91 Directory Entry Table ............................. 81 E External Fragmentation ........................... 8 F FAT .......................... See File Allocation Table FCFS ........................ See First Come First Serve FIFO .............................. See First In First Out File Allocation Table .............................. 75 File System ..................................... 65, 70 First Come First Serve ............................ 54 First In First Out ................................... 25 Fixed Partition Memory Allocation ............... 7 Fragmentation ....................................... 6 Frames ............................................... 13 H Holes ................................................... 9 I Independent Process .............................. 43 Inode ................................................. 81 Inode block ......................................... 81 Inter Process Communication ................... 43 Internal Fragmentation ........................... 8 J Jobs .................................................... 5 L Least Frequently Used ............................ 21 Least Recently Used .............................. 22 LFU ......................... See Least Frequently Used LRU ........................ See Least Recently Used M Memory ................................................ 2 Memory Management ............................... 5 Message Passing .................................... 44 Multiprocessing .................................... 45 Multiprogramming .............................. 6, 45 Multitasking......................................... 45 Multithreading ..................................... 50 N Non-Preemptive Multitasking .................... 48 Non-Preemptive Scheduling ..................... 54 Not Recently Used ................................. 23 NRU ............................ See Not Recently Used O Operating System .................................... 2 P Page Fault .......................................... 21 Page Replacement ................................ 21 page stealing ....................................... 27 Page Table .......................................... 15 Pages ................................................ 13 Physical Address Space ........................... 11 Preemptive Multitasking ......................... 48 Preemptive Scheduling ........................... 56 Priority Scheduling ............................ 60, 63 Process .............................................. 35 Process Life Cycle ................................. 38 R Re-Locatable Partition Memory Allocation ...... 9 Round Robin ........................................ 59 RR See Round Robin S Scheduling .......................................... 52 Segment Table ..................................... 31 shared memory .................................... 43 Shortest Job First .................................. 56 Signal Processing .................................. 45 Simple Paged Allocation .......................... 11 Simple Segmentation ......................... 29, 32 Single Contiguous Memory Allocation ............ 5 Infosys Technologies Limited Index
Version 1.0 100 Single Threading ................................... 50 SJF .............................. See Shortest Job First Software Interrupts ............................... 91 Spool ................................................. 93 Stack Region ........................................ 36 Super Block ......................................... 86 Swapping ............................................ 20 T Task .................................................. 35 Threads .............................................. 49 Time Stamping ..................................... 22 U Uniprogramming ..................................... 6 V Variable Partition Memory Allocation ............ 8 Virtual Memory ..................................... 18