Name: Md. Mohacel Hosen Id: 193071002 Department: CSE Batch: 22nd Semester: 7th Operating System (Over View) What is OS? Operating system is system software it works as an interface between user and hardware. In simple term it is an operating system is providing interaction between user and hardware. Example: Windows, Linux, Ubuntu, Mac OS/iOS, Android Word Processor Spreadsheets Compiler Text-Editor System/Application Programs OPERATING SYSTEM Computer Hardware CPU, Memory, I/O Devices ….. Web Browser If there is no operating system, we have to manually tell (code) the computer hardware each and everything that you have to do. Simple task like we need to save a file. For this task we need to tell the computer explicitly to the computer hardware what to do in the form of code, we have to write source code write codes for everything which is tedious and so difficult for average or non-technical person. That’s why operating system comes and makes this task for them to easy, how to save it & how to memory allocate so many things are done the operating system. Goal of OS Types of OS Batch OS Time Sharing OS Distributed OS Network OS Real Time OS Multiprogramming/ Processing/Tasking OS i) ii) ii) Convenience Efficiency Both Function of OS It is an interface between user & Hardware Allocation of Resources Management of Memory, Security, etc. Computer System Operation A modern general-purpose computer system consists of one or more CPU and number of device controllers connected through a common bus that provides access to shared memory. The CPU and the device controllers can execute concurrently, competing for memory cycles. To ensure orderly access to the shared memory, a memory controller is provided whose function is to synchronize access to the memory Some important terms: 1) Bootstrap Program: - The initial program that runs when a computer is powered up or rebooted. It is stored in the ROM. It must know how to load the OS and start executing that system. It must locate and load into memory the OS Kernel. 2) Interrupt: - The occurrence of an event is usually signaled by an Interrupt from Hardware or Software. Hardware may trigger an interrupt at any time by sending a signal to the CPU, usually by the way of the system bus 3) System Call (Monitor call): – Software may trigger an interrupt by executing a special operation called System Call. Storage Structure: Registers Expensive Fast but Cache Main Memory Smaller size Volatile Electronic Disk Cost per Bit increase Magnetic Disk Optical Disk Access Time increase Large Size Non-Volatile Magnetic Tapes If we need store anything for permanently we use secondary memory which is Hard Disk. So, whenever we execute something it gets loaded into the main memory otherwise it resides in the secondary memory. Main memory is RAM (Random Access Memory) and it is Volatile as compared to secondary memory which is non-volatile. Volatile: When the power of the devices is switched off then whatever was stored in these devices will be removed or erased. Non-Volatile: It retains it contains even the power is removed. I/O operation: I/O operations are accomplished through a wide assortment of external devices that provide a means of exchanging the data between the external environment and the computer. Inputs are the signals or data received by the system and outputs are the signals or data sent from it. System Call: System call is the programmatic way in which a computer program requests a service from the kernel of the operating system. System call provides an interface to the services made by Operating Systems. User Mode Kernel Mode User mode and kernel mode are two modes in which a program can execute. User Mode: If a program is executing in user mode then that program does not have direct access to the memory, to the hardware and such resources. Kernel Mode: If a program is executing in kernel mode then that program has the direct access to the memory, hardware and resources.(If kernel mode crush the entire system will be crush) So, we see that system calls are made by the program when it needs to access certain resources. When a program is executing in user mode and it needs to be switched to kernel mode for a particular time this system call is meet. Memory Management Memory management refers to management of Primary Memory or Main Memory. Main memory is a large array of words or bytes where each word or byte has its own address. Main memory provides a fast storage that can be accessed directly by the CPU. For a program to be executed, it must in the main memory. An Operating System does the following activities for memory management − Keeps tracks of primary memory, i.e., what part of it are in use by whom, what parts are not in use. In multiprogramming, the OS decides which process will get memory when and how much. Allocates the memory when a process requests it to do so. De-allocates the memory when a process no longer needs it or has been terminated. Processor Management In multiprogramming environment, the OS decides which process gets the processor when and for how much time. This function is called process scheduling. An Operating System does the following activities for processor management − Keeps tracks of processor and status of process. The program responsible for this task is known as traffic controller. Allocates the processor (CPU) to a process. De-allocates processor when a process is no longer required. Device Management An Operating System manages device communication via their respective drivers. It does the following activities for device management − Keeps tracks of all devices. Program responsible for this task is known as the I/O controller. Decides which process gets the device when and for how much time. Allocates the device in the efficient way. De-allocates devices. File Management A file system is normally organized into directories for easy navigation and usage. These directories may contain files and other directions. An Operating System does the following activities for file management − Keeps track of information, location, uses, status etc. The collective facilities are often known as file system. Decides who gets the resources. Allocates the resources. De-allocates the resources. Other Important Activities Following are some of the important activities that an Operating System performs − Security − By means of password and similar other techniques, it prevents unauthorized access to programs and data. Control over system performance − Recording delays between request for a service and response from the system. Job accounting − Keeping track of time and resources used by various jobs and users. Error detecting aids − Production of dumps, traces, error messages, and other debugging and error detecting aids. Coordination between other software’s and users − Coordination and assignment of compilers, interpreters, assemblers and other software to the various users of the computer systems. Operating system Structure (Multiprogramming/ Multitasking) An operating system must have two commonalties which is multiprogramming and multitasking Multiprogramming: Multiprogramming systems provide an environment in which the various system resources (for example, CPU, memory and peripheral devices) are utilized effectively but they do not provide for user interaction with the computer system. A single user cannot, in general keep either the CPU or the I/O devices busy at all times. Multiprogramming increases CPU utilization by organizing jobs (code and data) so that the CPU always has one to execute. Time Sharing (Multitasking): A time-shared operating system allows many users to share the computer simultaneously. In multitasking, multiple users are being entertainment by a common system. It means time of a single system is shared among different users. Note: CPU scheduling and Multiprogramming to prove each user with a small probation of a time-shared computer. Each user has at least one separation program in memory. A program loaded into memory and executing is called a “PROCESS” A computer processor is described as idle when it is not being used by any program. Simple structure: Such operating systems do not have well defined structure and are small, simple and limited systems. The interfaces and levels of functionality are not well separated. MS-DOS is an example of such operating system. In MS-DOS application programs are able to access the basic I/O routines. The monolithic Structure: It is an operating system is a very basic operating system in which file management, memory management, device management, and process management are directly controlled within the kernel. The kernel can access all the resources present in the system. Layered Structure: It is a type of system structure in which the different services of the operating system are split into various layers, where each layer has a specific well-defined task to perform. ... Example – The Windows NT operating system uses this layered approach as a part of it Microkernels: In this microkernel approach what happen is that we're having a microkernel. And from the name 'micro' itself means 'something small’. So, instead of having a big kernel with so many functionalities, what happens is that in this microkernel approach we remove all the non-essential components from the kernel and we implement them as system and user level program. Modules: A modular operating system is built with its various functions broken up into distinct processes, each with its own interface. ... The main elements of a modular operating system are a kernel and a set of dynamically loadable applications with their own discrete memory spaces. Process Synchronization When we have cooperating with process we want them to be synchronize between each other in such a way that there will be no data inconsistency but the data we’re having or the data we are sharing between process will remain consistent. There are two ways any process can execute – In Concurrent Execution – the CPU scheduler switches rapidly between processes. A process is stopped at any points and the processor is assigned to another instruction execution. Here, only one instruction is executed at a time. Parallel execution – 2 or more instructions of different process execute simultaneously on different processing cores. When several threads (or processes) share data, running in parallel on different cores, then changes made by one process may override changes made by another process running parallel. Resulting in inconsistent data. So, this requires processes to be synchronized, handling system resources and processes to avoid such situation are known as Process Synchronization. Critical Section: No two processes are executing in their critical sections at the same time. The critical-section problem is to design a protocol that the processes can use to Cooperate. When one process is executing in its critical section, no other process is to be allowed to execute in its critical section. Solution: A solution to the critical-section problem must satisfy the following three requirements: 1. Mutual exclusion: If process P; is executing in its critical section, then no other processes can be executing, in their critical sections. 2. Progress: If no process is executing in its critical section and some processes wish to enter their critical sections, then only those processes that are not executing in their remainder sections can participate in the decision on which will enter its critical section next, and this selection cannot be postponed indefinitely. 3. Bounded waiting: There exists a bound, or limit, on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted. Process Deadlocks in Operating System A deadlock happens in operating system when two or more processes need some resource to complete their execution that is held by the other process. In the above diagram, the process 1 has resource 1 and needs to acquire resource 2. Similarly process 2 has resource 2 and needs to acquire resource 1. Process 1 and process 2 are in deadlock as each of them needs the other’s resource to complete their execution but neither of them is willing to relinquish their resources. Coffman Conditions A deadlock occurs if the four Coffman conditions hold true. But these conditions are not mutually exclusive. The Coffman conditions are given as follows − Mutual Exclusion There should be a resource that can only be held by one process at a time. In the diagram below, there is a single instance of Resource 1 and it is held by Process 1 only. Hold and Wait A process can hold multiple resources and still request more resources from other processes which are holding them. In the diagram given below, Process 2 holds Resource 2 and Resource 3 and is requesting the Resource 1 which is held by Process 1. No Preemption A resource cannot be preempted from a process by force. A process can only release a resource voluntarily. In the diagram below, Process 2 cannot preempt Resource 1 from Process 1. It will only be released when Process 1 relinquishes it voluntarily after its execution is complete. Circular Wait A process is waiting for the resource held by the second process, which is waiting for the resource held by the third process and so on, till the last process is waiting for a resource held by the first process. This forms a circular chain. For example: Process 1 is allocated Resource2 and it is requesting Resource 1. Similarly, Process 2 is allocated Resource 1 and it is requesting Resource 2. This forms a circular wait loop. Deadlock Detection A deadlock can be detected by a resource scheduler as it keeps track of all the resources that are allocated to different processes. After a deadlock is detected, it can be resolved using the following methods − All the processes that are involved in the deadlock are terminated. This is not a good approach as all the progress made by the processes is destroyed. Resources can be preempted from some processes and given to others till the deadlock is resolved. Deadlock Prevention It is very important to prevent a deadlock before it can occur. So, the system checks each transaction before it is executed to make sure it does not lead to deadlock. If there is even a slight chance that a transaction may lead to deadlock in the future, it is never allowed to execute. Deadlock Avoidance It is better to avoid a deadlock rather than take measures after the deadlock has occurred. The wait for graph can be used for deadlock avoidance. This is however only useful for smaller databases as it can get quite complex in larger databases.