SAZ4B/SAE5A Operating System Unit : I - V
TM Unit I: Contents Views, Goals & Types of system OS Structure, Components & Services System Structures &Layered Approach Virtual Machines System Design and Implementation. Process Management & Scheduling Cooperating Process,Threads Interprocess Communication. CPU Scheduling criteria & Algorithms 1
TM OS VIEWS A modern computer consists of: One or more processors Main memory Disks Printers Various input/output devices. Managing all these varied components requires a layer of software the Operating System (OS). 2
TM OS GOALS Control/execute user/application programs. Make the computer system convenient to use. Ease the solving of user problems. Use the computer hardware in an efficient manner. 3
Types of Operating Systems TM 1. Realtime Operating System (RTOS) 2. Singleuser, Single task 3. Singleuser, multitasking 4. Multiuser 4
TM OS Structure OS Layer Structure gives the internal design of operating system. 5
OS ComponentsTM Components used in operating system. 6
TM OS-Services The following are examples of services provided by an operating system: Context Switching & Scheduling, Memory Management Inter-process Communication File Systems High level I/O facilities 7
OS System Structure TM Operating system internal system structure 8
OS Layered Structure TM Layers starts from layer 0 to layer N functions and operations in lower level layer Used for modularization of OS Higher level invokes lower level layers Less layers provide more functionality 9
TM Virtual Machines It is completely isolated guest Operating System It creates an illusion of multiple processors each capable of executing independently. It has two categories: 1. System virtual machines. 2. Process virtual machines 10
OS System Design and TM Implementation At the highest level, system design is dominated by the choice of hardware and system type. Beyond this level, the requirements can be divided into two groups: user goals, and system goals. User goals include convenience, reliability, security, and speed. System goals include ease of design, implementation, maintenance, flexibility, and efficiency. 11
Process Management TM 12
Process Scheduling TM A process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently. 13
Cooperating process TM A process is independent if it cannot affect other other process or be affected by it. Any process that does not share data with others is independent. Otherwise the process is cooperating. Cooperation is done to provide information sharing, computational speedups, modularity and convenience. 14
Threads & Interprocess TM Communication A thread of execution is the smallest sequence of programmed instructions that can be managed independently by a scheduler, which is typically a part of the operating system. Inter-process communication (IPC) refers specifically to the mechanisms an operating system provides to allow the processes to manage shared data. 15
TM Scheduling Criteria and Algorithm Scheduling Criteria Scheduling Algorithm CPU utilization Throughput Turnaround Time Waiting Time Response Time https://www.youtube.com/ watch?v=6txxa3hbx8y 16
TM Unit II: Contents Process Synchronization: Critical-Section problem Synchronization Hardware Semaphores Classic Problems of Synchronization Critical Region Deadlock Characterization Methods for handling Deadlocks Prevention, Avoidance, and Detection of Deadlock Recovery from deadlock 17
Process Synchronization Process Synchronization means sharing system resources by processes in a such a way that, Concurrent access to shared data is handled thereby minimizing the chance of inconsistent data 18
Critical Section Problem 19
Semaphores A semaphore is a variable or abstract data type used to control access to a common resource by multiple processes in a concurrent system such as a multiprogramming operating system. concurrent accesses to shared resources can lead to unexpected or erroneous behavior, so parts of the program where the shared resource is accessed are protected. This protected section is the critical section or critical region. Semaphores Critical Region 20
Classification Problem of Synchronization Dining Philosophers problem is an example of synchronization problem 21
Deadlock A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set. Example - System has 2 tape drives - P1 and P2 each hold one tape drive and each needs another one. https://www.youtube.com/watch?v=8dc6zz6fkda 22
Deadlock Characterization Deadlock can arise if four conditions hold simultaneously. 1. Mutual exclusion: at least one process must be held in a nonsharable mode. 2. Hold and wait: there must be a process holding one resource and waiting for another. 3. No preemption: resources cannot be preempted. 4. Circular wait: There must exist a set {p 0, p 1,...p n } of waiting processes such that p 0 is waiting for a resource which is held by p 1, p 1 is waiting for a resource which is held by p 2,..., p n-1 is waiting for a resource which is held by p n and p n is waiting for a resource which is held by p 0. 23
Methods for Handling Deadlock Ensure that the system will never enter a deadlock state. Allow the system to enter a deadlock state and then recover. Ignore the problem and pretend that deadlocks never occur in the system; used by most operating systems, including UNIX. 24
Prevention, Avoidance and Detection of Deadlock Deadlock Prevention. Disallow one of the four necessary conditions for deadlock. Deadlock Avoidance. Do not grant a resource request if this allocation have the potential to lead to a deadlock. Deadlock Detection. Always grant resource request when possible. Periodically check for deadlocks. If a deadlock exists, recover from it. Ignore the problem... Makes sense if the likelihood is very low. 25
Recovery from Deadlock Process Termination Abort all deadlocked processes: - Fast - A lot of process work is lost. Abort one deadlocked process at a time and check for deadlocks again: - More work to resolve a deadlock. - Better in terms of process work. - What is a good order to abort processes? Resource Preemption what is a good way to select a victim How can we rollback and then recover from preemption? How can we protect from starvation 26
TM Unit III: Contents Memory Management & Address Binding Dynamic Loading and Linking Overlays Logical and Physical Address Space Contiguous Allocation Internal & External Fragmentation Non Contiguous Allocation Paging and Segmentation schemes Implementation, Hardware Protection Sharing Fragmentation. 27
Memory Management Memory management is the function responsible for managing the computer's primary memory. The memory management function keeps track of the status of each memory location, either allocated or free. When memory is allocated it determines which memory locations will be assigned. 28
Address Binding Address binding is the process of mapping the program's logical or virtual addresses to corresponding physical or main memory addresses. 29
Dynamic Loading and Linking Dynamic loading is a mechanism by which a computer program can, at run time, load a library into memory, retrieve the addresses of functions and variables contained in the library A dynamic linker is the part of an operating system that loads and links the shared libraries needed by an executable program. 30
Overlays Overlaying is a programming method that allows programs to be larger than the computer's main memory. An embedded system would normally use overlays because of the limitation of physical memory, which is internal memory for a system-on-chip, and the lack of virtual memory facilities. 31
Logical and Physical Address Space Logical address space is set of logical addresses that generated by a program. The physical address is address that seen by memory unit and used to access memory units. Virtual addresses are mapped with physical addresses by memory management unit. 32
Contiguous Allocation Relocation-register scheme used to protect user processes from each other, and from changing operatingsystem code and data. Relocation register contains value of smallest physical address; limit register contains range of logical addresses each logical address must be less than the limit register. https://www.youtube.com/watch?v=uejwx ynip2m 33
Non Contiguous Allocation The Non-contiguous memory allocation allows a process to acquire the several memory blocks at the different location in the memory according to its requirement. The noncontiguous memory allocation also reduces the memory wastage caused due to internal and external fragmentation. As it utilizes the memory holes, created during internal and external fragmentation. 34
Internal & External Fragmentation The disadvantage of contiguous memory allocation is fragmentation. There are two types of fragmentation, namely, Internal fragmentation and External fragmentation. Internal Fragmenation - allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used.occurs when memory is allocated in fixed size pieces. External fragmentation - When the total memory space that is got by adding the scattered holes is sufficient to satisfy a request but it is not available contiguously, then this type of fragmentation is called external fragmentation. 35
Paging Physical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter is available - Avoids external fragmentation - Avoids problem of varying sized memory chunks Divide physical memory into fixed-sized blocks called frames - Size is power of 2, between 512 bytes and 16 Mb Divide logical memory into blocks of same size called pages - To run a program of size N pages, need to find N free frames and load program - Set up a page table to translate logical to physical addresses -- Backing store likewise split into pages Still have Internal fragmentation 36
Segmentation schemes A Memory Management technique in which memory is divided into variable sized chunks which can be allocated to processes. Each chunk is called a Segment. Advantages of Segmentation: - No Internal fragmentation. - Segment Table consumes less space in comparison to Page table in paging. Disadvantage of Segmentation: - As processes are loaded and removed from the memory, the free memory space is broken into little pieces, causing External fragmentation. https://www.youtube.com/watch?v=gjfiuj3lm2o 37
Hardware Protection I/O Protection : All I/O instruction should be privileged instructions. The user can only perform I/O operations through the OS Memory Protection : Protect the OS from access by users program, protect user programs from each other. CPU Protection : A timer to prevent a user program from getting stuck in an infinite loop. 38
Sharing Sharing is a technique which enables many people, located at various terminals, to use a particular computer system at the same time. Time-sharing or multitasking is a logical extension of multiprogramming. Processor's time which is shared among multiple users simultaneously is termed as time-sharing. Advantages of Timesharing operating systems are as follows Provides the advantage of quick response. Reduces CPU idle time. Disadvantages of Time-sharing operating systems are as follows Problem of reliability. Question of security and integrity of user programs and data. 39
Fragmentation Reduce external fragmentation by compaction - Shuffle memory contents to place all free memory together in one large block - Compaction is possible only if relocation is dynamic, and is done at execution time Now consider that backing store has same fragmentation problems. Types of Fragmentations External Fragmentation total memory space exists to satisfy a request, but it is not contiguous Internal Fragmentation allocated memory may be slightly larger than requested memory; this size difference is memory internal to a partition, but not being used. 40
TM Unit IV: Contents Virtual Memory Demand Paging Page Replacement Algorithms Thrashing File System Concepts & Access methods Directory Structure Protection Consistency Semantics File System Structures Allocation methods Free Space Management 41
Virtual Memory o Virtual memory is a common part of operating system on desktop computers. o The team virtual memory refers to something which appears to be present but actually it is not o The virtual memory technique allows users to use more memory for a program than the real memory of a computer. 42
Demand Paging Demand paging is a method of virtual memory management. In a system that uses demand paging, the operating system copies a disk page into physical memory only if an attempt is made to access it and that page is not already in memory. It follows that a process begins execution with none of its pages in physical memory, and many page faults will occur until most of a process's working set of pages is located in physical memory. 43
Page Replacement Algorithm When a fault occurs, the OS loads the faulted page from disk into a page of memory. At some point, the process has used all of the page frames it is allowed to use. When this happens, the OS must replace a page for each page faulted in. That is, it must select a page to throw out of primary memory to make room. How it does this is determined by the page replacement algorithm. The goal of the replacement algorithm is to reduce the fault rate by selecting the best victim page to remove. 44
Thrashing If a process does not have enough pages, the page-fault rate is very high low CPU utilization OS thinks it needs increased multiprogramming adds another process to system Thrashing is when a process is busy swapping pages in and out 45
File System Concepts File System Interface The user level (more visible) portion of the file system. Access methods Directory Structure Protection File System Implementation The OS level (less visible) portion of the file system. Allocation and Free Space Management Directory Implementation https://www.youtube.com/watch?v=mzuymy7ihk0 46
File System- Access Methods Sequential access read all bytes/records from the beginning cannot jump around, could rewind or back up convenient when medium was magenatic tape Random access bytes/records read in any order essential for data base systems read can be move file marker (seek), then read or read and then move file marker https://www.youtube.com/watch?v=zg-t2zqq9ye 47
Directory Structure A single level directory system Two level directory system Tree directory system Single level directory system Two level directory system Tree directory system 48
File System Structures Three kinds of files byte sequence record sequence tree (a) An executable file (b) An archive 49
Allocation Methods The main idea behind allocation is effective utilization of file space and fast access of the files. There are three types of allocation: - contiguous allocation - linked allocation - Indexed allocation To keep track of the free space, the file system maintains a free-space list which tracks all the disk blocks which are free. To create a file, the required space is reserved for the file and the corresponding space is removed from the free list linked to each other. 50
Free Space Management 51
TM Unit V: Contents I/O Systems Overview I/O Hardware Application I/O Interface Kernel I/O subsystem Transforming I/O Requests to Hardware Operations Performance of I/O System Secondary Storage Structures Protection, Goals, Domain Access matrix Security problem, Authentication Threats, Threat Monitoring, Encryption 52
I/O System - Overview I/O management is a major component of operating system design and operation Important aspect of computer operation I/O devices vary greatly Various methods to control them Performance management New types of devices frequent Ports, busses, device controllers connect to various devices Device drivers encapsulate device details Present uniform device-access interface to I/O subsystem 53
I/O hardware Incredible variety of I/O devices Storage Transmission Human-interface Common concepts signals from I/O devices interface with computer Sometimes integrated Sometimes separate circuit board (host adapter) Contains processor, microcode, private memory, bus controller, etc Some talk to per-device controller with bus controller, microcode, memory, etc 54
Application I/O Interface I/O system calls encapsulate device behaviors in generic classes Device-driver layer hides differences among I/O controllers from kernel New devices talking already-implemented protocols need no extra work Each OS has its own I/O subsystem structures and device driver frameworks Devices vary in many dimensions Character-stream or block Sequential or random-access Synchronous or asynchronous (or both) Sharable or dedicated Speed of operation read-write, read only, or write only 55
Kernel I/O Subsystem Scheduling Some I/O request ordering via per-device queue Some OSs try fairness Some implement Quality Of Service (i.e. IPQOS) Buffering - store data in memory while transferring between devices To cope with device speed mismatch To cope with device transfer size mismatch To maintain copy semantics Double buffering two copies of the data Kernel and user Varying sizes Full / being processed and not-full / being used Copy-on-write can be used for efficiency in some cases 56
Transforming I/O Requests to Hardware Operations Consider reading a file from disk for a process: Determine device holding file Translate name to device representation Physically read data from disk into buffer Make data available to requesting process Return control to process 57
I/O System Performance I/O a major factor in system performance: Demands CPU to execute device driver, kernel I/O code Context switches due to interrupts Data copying Network traffic especially stressful To improve performance - Reduce number of context switches - Reduce data copying - Reduce interrupts by using large transfers, smart controllers, polling - Use DMA - Use smarter hardware devices - Balance CPU, memory, bus, and I/O performance for highest throughput 58
Secondary Storage Structures Main memory only large storage media that the CPU can access directly. Secondary storage Extension of main memory that provides large nonvolatile storage capacity. Magnetic disks Rigid metal or glass platters covered with magnetic recording material. - Disk surface is logically divided into tracks, which are subdivided into sectors. - The disk controller determines the logical interaction between the device and the computer 59
Storage Protection Security and Protection services Protect OS from users Protect users from other users Prevent unauthorized entry to system Prevent unauthorized system use y authorized users. https://www.youtube.com/watch?v=h9kv2emjzxe 60
Storage System - Goals Describe factors that determine storage device performance. Choose appropriate secondary storage devices and their technologies Outlines characteristics common to all storage devices. Explains the technology strengths and weaknesses of primary storage an secondary storage. https://www.youtube.com/watch?v=kmets6onooi 61
Domain Access matrix CPU does not transfer data, only initiates operation DMA controller transfers data directly to/from main memory Interrupts when transfer completed Input protocol: https://www.youtube.com/watch?v=soy8fwt5uo4 62
Storage security problem Secure : resources use an accessed as intended under all circumstances Intruders (Crakers) : attempt to breach security Threat is potential security violation Attack is attempt to breach security Attack can e accidental or malicious Easier to protect against accidental than malicious. 63
Authentication Authentication is a process in which the credentials provided are compared to those on file in a database of authorized users information on a local operating system or within an authentication server. If the credentials match, the process is completed and the user is granted authorization for access. Types of Authentications User authentication Machine authentication Password-based authentication 64
Threats System threats refers to misuse of system services and network connections to put user in trouble. System threats can be used to launch program threats on a complete network called as program attack. System threats creates such an environment that operating system resources/ user files are misused. Following is the list of some well-known system threats. Worm Worm is a process which can choked down a system performance by using system resources to extreme levels. Port Scanning Port scanning is a mechanism or means by which a hacker can detects system vulnerabilities to make an attack on the system. Denial of Service Denial of service attacks normally prevents user to make legitimate use of the system. For example, a user may not be able to use internet if denial of service attacks browser's content settings. 65
Threat Monitoring Check for suspicious patterns of activity i.e., several incorrect password attempts may signal password guessing. Audit log records the time, user and type of all accesses to an object Scan the system periodically for security holes, done when the computer is relatively unused. 66
Encryption The translation of data into a secret code. Encryption is the most effective way to achieve data security. To read an encrypted file, you must have access to a secret key or password that enables you to decrypt it. Unencrypted data is called plain text ; encrypted data is referred to as cipher text. There are two main types of encryption: 1. Asymmetric encryption (also called public-key encryption) 2. Symmetric encryption. https://www.youtube.com/watch?v=beb_anpwpwy 69