Introduction to Operating Systems PDF
Document Details
Uploaded by RoomierSonnet
2024
Imen Merdassi
Tags
Related
Summary
This document provides an introduction to operating systems. It covers basic computer elements, computer architecture, software, and operating system roles. The document also details memory management, process management, file management, and various operating systems types.
Full Transcript
INTRODUCTION TO OPERATING SYSTEM Imen Merdassi 1 Academy year: 2024/2025 2 BASIC ELEMENTS At a top level, a computer consists of: One or more processors Memories Clocks Disks Network connection interfaces Input/output peripherals Buse...
INTRODUCTION TO OPERATING SYSTEM Imen Merdassi 1 Academy year: 2024/2025 2 BASIC ELEMENTS At a top level, a computer consists of: One or more processors Memories Clocks Disks Network connection interfaces Input/output peripherals Buses 4 COMPUTER BASICS: INSIDE A COMPUTER What is the main component that contains the most important parts of a computer? A) Processor B) Motherboard C) RAM D) Hard drive What is the processor commonly known as? A) Hard drive B) RAM C) CPU (Central Processing Unit) D) Graphics card 6 COMPUTER BASICS: INSIDE A COMPUTER What component helps keep the processor cool? A) Motherboard B) Battery C) Heatsink D) Power supply What type of memory is erased when you turn off the computer? A) Hard drive B) RAM (Random Access Memory) C) SSD D) Cache memory 7 COMPUTER BASICS: INSIDE A COMPUTER Which type of storage is faster and more durable but also more expensive? A) Hard drive with magnetic platter B) Solid State Drive (SSD) C) RAM D) USB drive What is the purpose of expansion slots on a desktop motherboard? A) To increase power B) To connect the processor C) To upgrade with additional components like video or wireless cards D) To store more data 8 COMPUTER BASICS: INSIDE A COMPUTER What is the function of the power supply in a computer? A) Store data B) Provide electricity to components C) Process information D) Manage wireless connections What allows laptops to operate without being plugged into a power outlet? A) RAM B) CPU C) Battery D) Power supply 9 COMPUTER ARCHITECTURE Processor: Controls the operation of the computer and performs its data processing functions. When there is only one processor, it is often referred to as the central processing unit (CPU). 10 COMPUTER ARCHITECTURE Main memory: Stores data and programs. This memory is typically volatile; that is, when the computer is shut down, the contents of the memory are lost. In contrast, the contents of disk memory are retained even when the computer system is shut down. Main memory is also referred to as real memory or primary memory. 11 COMPUTER ARCHITECTURE I/O modules: Move data between the computer and its external environment. The external environment consists of a variety of devices, including secondary memory devices (e.g., disks), communications equipment, and terminals. 12 COMPUTER ARCHITECTURE System bus: Provides for communication among processors, main memory, and I/O modules. 13 SOFTWARE They can be classified into two categories: User application programs System programs : enable the computer to function 14 Operating Systems: The Foundation of Computing Imagine a bustling city, teeming with activity, where traffic flows smoothly, communication is seamless, and resources are managed efficiently. This is analogous to an operating system, the unseen yet indispensable software that manages a computer's hardware and software resources, enabling seamless operations and interactions between users and the digital world. OS Why an OS? Overview Virtual machine: Hiding the tedious bits of hardware to provide an easy-to-use interface. Resource Management: Organize and control the allocation of processors, memories, icons and windows, peripherals, and networks among the programs that use them. Assist user programs and protect users in the case of shared usage. 16 OS ROLE 17 Functions of an Operating System 1 Memory Management 2 Process Management Resource management in an operating system (OS) refers to The operating system oversees the execution of programs, the allocation and control of various hardware and software known as processes. It manages the creation, scheduling, and resources to ensure that processes can operate efficiently and termination of processes, ensuring that they operate efficiently effectively. and without interference. 3 File System Management 4 Security and Protection The operating system manages the hierarchical structure of files The operating system acts as a security guard, protecting the and directories, allowing users to organize, access, and computer from unauthorized access, malicious software, and manipulate data effectively. It provides mechanisms for data breaches. It implements user authentication, access control, creating, deleting, and modifying files, ensuring data integrity. and security measures to safeguard sensitive information. MEMORY MANAGMENT 19 MEMORY MANAGMENT Persistent memory stored on the hard disk. Organized into files and directories. File - sequence of bytes identified by its name. Directory - allows files to be classified in a hierarchy. 20 MEMORY MANAGMENT Memory: store code and data of the process during its execution Role of the OS Load a process into memory Free memory at the end of a process execution Allocate and free memory dynamically requested by processes → Optimally for the CPU 21 PROCESS MANAGEMENT A process is an instance of a program in execution, which includes the program code, its current activity, and associated resources (like memory and file handles). Role of the operating system for processes: (Re)activate a process. Suspend a process Kill a process Control the execution of a process in an optimal way for the CPU. 22 PROCESS MANAGEMENT 23 FILE MANAGEMENT File Elementary unit of resource management. Used for data storage on hard disk and for managing input/output. File Characteristics Types Access rights Structure 24 FILE MANAGEMENT Role of the OS Creation Modification - Reading - Writing Deletion 25 HISTORY 26 Types of Operating Systems Desktop Operating Systems Mobile Operating Systems Server Operating Systems Desktop operating systems are Mobile operating systems are Server operating systems are designed for personal computers specifically tailored for designed for powerful computers and provide a user-friendly smartphones and tablets. They that provide services to multiple interface for interacting with offer touch-based interfaces, users over a network. They focus applications and managing files. optimized for smaller screens, on reliability, scalability, and Examples include Windows, and focus on mobile-specific security to handle complex macOS, and Linux distributions. features and applications. workloads and manage network Examples include Android, iOS, resources. Examples include and Windows Phone. Windows Server, Linux distributions, and macOS Server. Windows Operating System User-Friendly Interface Wide Software Compatibility Windows offers a familiar and intuitive graphical user interface, Windows boasts a vast library of software applications, from making it easy for users to navigate and interact with applications. It productivity tools and games to creative software and utilities. This includes features like the Start menu, taskbar, and file explorer for wide compatibility ensures users have access to a diverse range of convenient access and management. programs. Strong Security Features Regular Updates Windows has robust security features, including built-in antivirus Microsoft regularly releases updates and patches for Windows to protection, firewall, and user account controls, to protect users from address security vulnerabilities, improve performance, and add new malware, unauthorized access, and data breaches. features. These updates ensure the operating system remains secure and up-to-date. macOS Operating System 1 Elegant Design and User 2 Seamless Integration Experience with Apple Devices macOS emphasizes aesthetics and macOS works seamlessly with ease of use, with a clean, other Apple devices, such as minimalist interface and intuitive iPhones, iPads, and Apple features. It prioritizes design Watches. This integration allows consistency and visual appeal, for smooth data transfer, syncing, creating a pleasant user experience. and cross-device communication. 3 Strong Security and Privacy4 Focus on Creativity and Productivity macOS has a reputation for strong security and privacy features, macOS offers powerful creative including robust built-in protection and productivity tools, including against malware and data breaches. iMovie, GarageBand, Pages, It also provides granular controls Numbers, and Keynote, making it a for user privacy and data sharing. popular choice for professionals and hobbyists. Linux Operating System Open Source Stability and Reliability Linux is open-source software, meaning Linux is renowned for its stability and its source code is freely available for reliability. It is often used in servers and modification and distribution. This allows embedded systems where uptime and for community-driven development, performance are critical. innovation, and customization. Flexibility and Customization Strong Community Support Linux offers a high degree of flexibility, Linux has a large and active community allowing users to customize the operating of developers and users. This community system to meet their specific needs. It can provides extensive documentation, be tailored for various hardware support forums, and resources for configurations and software troubleshooting and learning. environments. Mobile Operating Systems Touch-Based Interfaces Mobile operating systems are designed for touch-based interactions, with intuitive gestures and controls optimized for smaller screens. They prioritize user-friendliness and ease of use. App Stores and Ecosystems Mobile operating systems have thriving app stores where users can download and install a vast library of applications, tailored for specific needs and interests. Mobile-Specific Features They offer features optimized for mobile devices, such as GPS navigation, camera integration, and mobile data connectivity, enhancing the user experience. Constantly Evolving Mobile operating systems are constantly evolving with new features, security updates, and software improvements, ensuring a smooth and secure user experience. Process Management and Scheduling Imen Merdassi What is a Process? 1 Fundamental 2 Dynamic and Unit of Independent Execution A process is the basic unit of Processes are dynamic execution in an operating entities that can be created, system. It represents a running executed, and terminated program, complete with its independently, allowing the own memory allocation, operating system to manage system resources, and multiple concurrent tasks execution state. efficiently. 3 Encapsulation of Resources Each process is allocated its own set of resources, including CPU time, memory, and input/output devices, ensuring isolation and independence from other running processes. Process States and Transitions New 1 A process begins its life cycle in the "New" state, where it is created and its initial resources are allocated by the operating system. 2 Ready The process transitions to the "Ready" state when it is eligible for execution, awaiting its turn to be Running 3 scheduled on the CPU. In the "Running" state, the process is actively executing its instructions, utilizing the CPU resources allocated to it. 4 Waiting The process enters the "Waiting" state when it requires a specific system resource or event, such as Terminated 5 input/output completion, before it can continue its Finally, the process reaches the "Terminated" state execution. when it has completed its execution or has been forcibly terminated by the operating system. PROCESS STATES AND TRANSITIONS PROCESS CONTROL BLOCK (PCB) The full status of a process is captured by its Process Control Block (PCB), which contains: Process state — running, waiting, etc. Program counter — location of instruction to next execute CPU registers — contents of all process-centric registers CPU scheduling information — priorities, scheduling queue pointers Memory-management information — memory allocated to the process Accounting information — CPU used, clock time elapsed since start, time limits I/O status information — I/O devices allocated to process, list of open files All process PCBs are maintained by the OS using dedicated data structures. Process Control Block (PCB) Process Identifier Execution State The Process Control Block The PCB maintains the current (PCB) is a data structure that state of the process, such as stores all the essential whether it is running, ready, or information about a process, waiting, as well as the process' including its unique process priority and scheduling identifier (PID). information. Resource Allocation CPU Accounting The PCB tracks the resources The PCB also records the CPU allocated to the process, time used by the process, which including memory addresses, is crucial for accounting, open files, and input/output scheduling, and resource devices, allowing the operating management decisions made by system to manage and monitor the operating system. these resources. Process Creation and Termination Process Creation When a new process is created, the operating system allocates resources such as memory and system IDs, loads the program code and data, and initializes the process control block (PCB). Process Execution The created process is then added to the ready queue, where it waits to be scheduled and executed by the CPU, utilizing the resources allocated to it. Process Termination When a process completes its execution or is forcibly terminated by the operating system, its resources are reclaimed, and the process control block is removed from the system. Inter-process Communication (IPC) Shared Memory Message Queues Pipes and Sockets Processes can communicate Processes can send and Processes can also by sharing a region of receive messages through communicate using pipes, memory, allowing them to message queues, which act which provide a read and write data directly as intermediaries, unidirectional flow of data, without the need for system facilitating asynchronous or sockets, which enable calls. communication between network-based them. communication between processes. CPU Scheduling 1 Efficient 2 Scheduling Policies Resource Operating systems employ various Allocation CPU scheduling is the process of scheduling algorithms, such as First- determining which process should be Come First-Served (FCFS), Shortest- executed by the CPU at a given time, Job-First (SJF), and Round-Robin (RR), ensuring the optimal utilization of each with its own strengths and trade- system resources and meeting the offs in terms of fairness, response time, performance requirements of running and throughput. processes. 3 Preemptive vs. Non-preemptive Scheduling can be either preemptive, where the CPU can be taken away from a running process, or non-preemptive, where a process runs to completion once it's granted the CPU. Scheduling Algorithms First-Come First- Shortest-Job-First (SJF) Round-Robin (RR) Served (FCFS) The SJF algorithm selects the The Round-Robin algorithm The FCFS algorithm simply process with the shortest divides the CPU time into executes processes in the order expected execution time, which small, equal-sized slices and they arrive, with no can improve overall system allocates them to processes in consideration for process throughput. However, it may a circular fashion. This priority or execution time. starve longer processes and is ensures fairness and While simple to implement, it not suitable for real-time responsive scheduling, but can lead to poor responsiveness applications. may result in higher average and resource utilization. waiting times. Preemptive vs. Non-preemptive Scheduling Non-preemptive Preemptive In non-preemptive scheduling, a process runs to Preemptive scheduling allows the operating system to completion once it's granted the CPU, even if a interrupt a running process and switch to a higher-priority higher-priority process becomes available. This can process, ensuring timely response to critical tasks. This lead to poor responsiveness but is simpler to approach is more complex but offers better overall system implement. performance. FIRST-COME FIRST-SERVED (FCFS) Basic Concept is a non preemptive scheduling algorithm that handles jobs according to their arrival time: the earlier they arrive, the sooner they're served. It's a very simple algorithm to implement because it uses a FIFO queue. In a strictly FCFS system there are no WAIT queues (each job is run to completion). IMPLEMENTATION (FCFS) 1. Input the processes along with their burst time (bt). 2. Find waiting time (wt) for all processes. 3. As first process that comes need not to wait so waiting time for process 1 will be 0 i.e. wt = 0. 4. Find waiting time for all other processes i.e. for process i -> wt[i] = bt[i-1] + wt[i-1]. 5. Find turnaround time = waiting_time + burst_time for all processes. 6. Find average waiting time = total_waiting_time / no_of_processes. 7. Similarly, find average turnaround time = total_turn_around_time / no_of_processes. SHORTEST-JOB-FIRST (SJR) SCHEDULING Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time. Two schemes: – nonpreemptive – once CPU given to the process it cannot be preempted until completes its CPU burst. – preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time- First (SRTF). SJF is optimal – gives minimum average waiting time for a given set of processes. PRIORITY SCHEDULING A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer = highest priority). – Preemptive – nonpreemptive SJF is a priority scheduling where priority is the predicted next CPU burst time. Problem = Starvation – low priority processes may never execute. Solution = Aging – as time progresses increase the priority of the process. ROUND ROBIN (RR) Each process gets a small unit of CPU time (time quantum), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n -1)q time units. Performance – q large = FIFO – q small = q must be large with respect to context switch, otherwise overhead is too high. PROJECT 1. program and simulate scheduling algorithms discussed before: FCFS Shortest-Job-First (SJR) Scheduling Preemptive SJF Priority Scheduling Round Robin (RR) All scheduling algorithm shall be programmed in one file (all in one) so that once you submit no. of process, process's name and burst time, it should display options to see waiting time, turnaround time, avg. waiting and avg. turnaround time for scheduling alg. Presented above. THREADS Thread vs. Process – A thread is a dispatchable unit of work (lightweight process) that has independent context, state and stack – A process is a collection of one or more threads and associated system resources – Traditional operating systems are single-threaded systems – Modern operating systems are multithreaded systems THREADS The thread has: – A program counter that keeps track of which instruction to execute next. – Has registers which hold its current working variables – Has a stack which contains the execution history Processes are used to group resources together. Threads are the entities scheduled for execution on the CPU. THREADS What threads add to the process model is to allow multiple executions to take place in the same process environment. Having multiple threads running in parallel in one process is analogous to having multiple processes running in parallel in one computer. – In the former case the threads share an address space, open files, and other resources. – In the later case processes share physical memory, disks, printers and other resources. THREADS Threads are sometimes called lightweight process. Multithreading- is to describe the situation of allowing multiple threads in the same process. SINGLE AND MULTITHREADED PROCESSES… A thread is a single sequence of execution within a program Multithreading refers to multiple threads of control within a single program – each program can run multiple threads of control within it, e.g., Web Browser, MS Words,… MULTITHREADING MODELS Many-to-One One-to-One Many-to-Many