TCS Aspire- Chapter 4

download TCS Aspire- Chapter 4

If you can't read please download the document

description

Notes for TCS Aspire Course Chapter 4 of Module 1 on Introduction to Computers.

Transcript of TCS Aspire- Chapter 4

4. Introduction to Operating system- OS is a collection of programs. It is a software that supports computer's basic functions.- OS acts as an interface between applications and computer hardware.- OS also manages the computer hardware by creating a uniform set of functions that can be performed on various classes of devices. These functions rely on a layer of drivers that provide specific means to carry out operations on specific hardware.- OS is the core software component of a computer. It performs many functions and acts as interface between computer and outside world.- OS provides interface to hardware by use of drivers.- OS basically manages all internal components of a computer. It was developed to better use the computer.4.1 Basic Resources managed by OSFollowing are the basic resources managed by OS:- Memory Space (Memory Management)- CPU time (Process Management)- Disk Space (File System Management)- Input-output device (Device Management)4.1a Basics of Memory Management- any program needs to be loaded in RAM before it can be executed. RAM is computer memory that can be accessed randomly.- Memory Management deals with managing computer's primary memory. It decides the amount of memory to be allocated to a particular program.- it also keeps track of the free as well as allocated memory. Memory management applies ONLY to RAM.- aim is to utilize the available memory effectively. Fragmentation should be minimized.i) Fragmentation- occurs when there are many free small blocks in memory that are too small to satisfy any request.- it is a phenomenon in which storage space is used inefficiently resulting in reduced capacity and performance. Also leads to wastage of storage space.Types of Fragmentation- External, Internal, Data- can be present in isolation or conjunction.- when a program starts, there are long and contiguous free memory areas. Over time and with use these become fragmented into smaller areas and eventually it becomes impossible for program to request large paritions of memory.Internal Fragmentation- it is the space wasted inside the allocated memory block because of the restriction on allowed sizes of allocated blocks. Allocated memory can be slightly larger than requested memory.- the size difference is the memory internal to partition but would not be used. Design change is the best way to remove internal fragmentation. Example, by using dynamic allocation.External Fragmentation- happens when dynamic memory allocation algorithm allocates some memory and a small piece is left over which cannot be used effectively.- the amount of usable memory reduces drastically if too much external fragmentation occurs. Total memory available is enough to satisfy a request but it is not contiguous so it is wasted.Data Fragmentation- occurs when a collection of data in memory is broken up into many pieces that are not close enough. It is typically the result of attempting to insert a large object into storage that has already suffered external fragmentation.ii) Memory Management Techniques> Single Contiguous Allocation> Partitioned Memory Management Scheme> Paged Memory Management> Segmented Memory ManagementSingle Contiguous Allocation- simplest type of memory management in which all memory except a small portion is available for a program to run. So only one program is loaded and remaining memory is wasted. Ex: MS-DOS- advantage is that it supports fast sequential and direct access and provides good performance as number of disk seeks are minimum.- disadvantage is that it causes fragmentation.Partitioned Memory Management Scheme- divides primary memory into multiple memory partitions, usually contiguous memory areas. Memory management is that a particular partition is allocated to a program when it starts and is deallocated when it ends.- A is the base register address which is the lowest address a process may refer to. Length of a partition can be found from the Bounds register. Bounds register stores the lower and upper bound of addresses in time sharing environment.- time sharing environment refers to the use of computer by multiple users at the same time.>Fixed Memory Partitioning (Static Partitioning)- main memory is divided into a number of static partitions and a process may be loaded into a partition of equal or greater size.- advantage is simplicity in implementation and little overhead. Disadvantage is internal fragmentation, also maximum number of processes are fixed.>Variable Memory Partitioning (Dynamic Partitioning)- partitions are created dynamically so that all processes are loaded in paritions having equal size as that of process.- advantage is no internal fragmentation and efficient use of memory, disadvantage is external fragmentation.Paged Memory Management- divides primary memory into fixed size units known as page frames. Program's address space is divided into pages of same size.- in this, each process runs in it's own memory space. Advantage is that there is no external fragmentation but a little of internal fragmentation.- CPU generates a page number which is indexed in a page table. The corresponding entry in page table gives the frame number which is then added to the displacement(offset, same as that for page number) to get the final physical address.Segmented Memory Management- computer's main memory is divided into segments. In this, there is a referece to memory location that includes a value. This value identifies a segment and an offset within that segment.- this scheme does not provide single contiguous memory allocation.- segmentation allows better access protection than other schemes because references are relative to a segment and offset that is not in that segment will not be allowed.- Segmentation with paging eliminates external fragmentation and has the ability to handle growing data.4.1b Process Management- CPU has multiple processes running at a time and many are waiting in queue to be executed. CPU should schedule all these processes.Process creation involves four principle events:> System initialization or start up.> A process is run to execute a process creation system call.> Request to create a new process is issued by user.> Batch job initiation, when a batch is finished and CPU has enough resources for next process, it in initialized.- foreground processes are those that interact directly with the user, like taking input or showing output.- backgroud processes are those, that do not interact directly with user, like showing clock etc.- common reasons for program termination are: user log off, normal termination, error and fault, time limit exceed, memory unavailable, I/O failure.Pre-emptive Scheduling- a running task is interrupted in between its execution because a higher priority task is required to be completed.- the interrupted task is either blocked or put in suspended state and resumed later.Non pre-emptive Scheduling- a running task executes till it completes fully. It cannot be interrupted before it completes its servicing.- ready state of a process means that it is ready to be executed. It is loaded in memory and is waiting for the processor.- running state is a state in which a process is currently running. It can be moved to suspended state and resumed later.- a process may be blocked due to reasons such as when a particular process has exhausted, the CPU time allocated to it, it is waiting for an event to occur. They can move to either ready or suspended state.- suspended state: a process moved from main memory to virtual memory. Can be later moved to ready state.- process keeps on changing states unless it reaches termination.4.1c File System Management- helps to manage and organize the files in such a way that their retrieval is faster and easier.- file system manager is used by the OS to do file system management. It keeps track of all files and directories on secondary storage media.- OS does the following for a efficient file management:> able to identify numerous files by giving unique names to them.> maintains a list to keep track of exact file location.> provides fast and simple algorithms to write and read files in cooperation with device manager.> grant and deny access rights to programs and users.> allocate and de-allocate files so that they can be processed.> provide programs and users with simple commands for handling files.- on storage media, files are saved in blocks or sectors. To access these, file manager and device manager works together.- device manager knows where to find each sector on disk, but only file manager has a list telling in what sectors either file is stored.- this list is called File Allocation Table(FAT). It has been in use under DOS for a long time.Contiguous File Allocation- at the time of file creation, a single set of blocks is allocated to a file and each file is stored contiguously in sectors, one sector after another.- advantage is that FAT has a single entry for each file consisting of start address, length and name, and it is easy to get a single block because its address can be easily calculated.- disadvantage may be that it can be difficult to get a sufficiently large block of contiguous memory block.- now it is used only in tapes and recordable CDs.Non-contiguous File Allocation- all blocks of a file can be distributed all over the storage. The FAT also has an entry for each sector the file occupies.- advantage is that it is easy to get a single block, because each block has its entry in FAT, and it is a simple allocation method where no overhead is produced and no search method for free blocks in needed.- disadvantage is that compaction is required from time to time as FAT becomes enormous which can slow down the system.- used in MS-DOSChained Allocation- only the first block of the file gets an entry in the FAT, each sector has data as well as pointer to the next sector to be accessed after it.- advantage is that FAT has a single entry for each file and there is no need to store the files contiguously.- disadvantage is that it takes much time to receive a single block because that information is neither stored anywhere not can it be calculated. If a particular sector is to be accessed, then all its previous sectors are required to be accessed.- used in Unix i-node which is an OS that used i-nodes as its data structures.Indexed Allocation- only the first block gets entry in FAT and no data is stored in this sector. It only has pointers to where the file is on a storage medium. That is why, first block is called the index block.- advantage is that retrieving a single block is easy because information about it is stored in first block.- disadvantage is that for each file an additional sector is needed to keep track of the location of a file.- a very small always occupies two blocks, where as data cold have easily fitted in one. This results is space wastage.- implemented in UNIX systems. It is reliable as well as fast.4.1d Device Management- OS also deals with device management, specially I/O devices. In a multi user system, there are shared devices and management of these by sending appropriate commands is major task of OS.- a software routine that knows how to deal with each device is called a driver and OS requires drivers for the peripherals attached to computer. When a new peripheral is added, device driver is installed into the operating system.- OS also deals with the access time of these devices, it helps make the device access fast and in the most efficient way possible.- major concern is to prevent deadlock situation.Dead Lock- it is a situation where each set of processes is waiting for an event that only other process in the set can cause.- Process 1 requires printer that is being used in Process 2 and Process 2 requires monitor which is used by Process 1.- this causes an indefinite wait for processes leading to a situation known as deadlock.- mutex: mutual exclusion object which is a logical unit. It is a program object that allows multiple program threads to share the same resource but not simultaneously. File access is an example of mutex.- strategies for dealing with deadlock:> ostrich algorithm: ignoring the problem altogether. It assures that ignoring the problem would be more cost-effective as compared to allowing the problem to occur and then attempt its prevention.> Detection and Recovery.> Avoiding deadlock by careful resource allocation.> Prevention of deadlock by structurally negating one of the 4 necessary conditions.Necessary conditions of deadlock- mutual exclusion: resouces involved are non sharable.- Hold and wait: requesting process hold resources while waiting for requested resources.- No pre-emptive condition: resources already allocated to a process cannot be pre-empted.- Circular wait: process in the system forms a circular list or chain where each process in the list is waiting for a resource held by next process in list.4.2 Resource Sharing Management- primary task of OS is to keep track of resources like memory, CPU utilization, storage device, and I/O devices, to grant resource reqests, to mediate conflicting requests from different programs etc.4.2.1 Multiplexing- method by which multiple analog data signals/ digital data streams are combined into one signal over a shared medium. It is used to share an expensive resourve and this help reduce cost.- Communication channel is used for transmission of a multiplexed signal, this channel may be a physical transmission medium. Multiplexing basically works on the principle of division of signals.- capacity of the channel is divided into several low level logical channels. Each channel maps to each message signal or data stream to be transferred.- reverse of this process is called demultiplexing. It can extract the original channels or signals on the receiver side.- device that performs the task of multiplexing is called a multiplexer and a device that performs demultiplexing is called demultiplexer.Time Multiplexing- when different programs/users get their turn to use that resource one after another.- turns for usage are decided as per the predefined operating system algorithm.- it is used in printer.Space Multiplexing- the resource is shared equally in the available space. Time period for which the resource is used does not matter anymore.- each gets a part of the resource. Hard disk, main memory etc are examples of space multiplexing.GLOSSARYScheme- scheme in documents refers to techniques.Process- job or a program that executes in memory.Data Array- ordered list of itemsData Structure- particular way of storing and organizing data in a computer so that it can be used efficiently.