Operating Systems Lecture Notes PDF
Document Details
Uploaded by PhenomenalSanDiego
Tags
Summary
These lecture notes cover fundamental operating system concepts, including process management, memory management, and resource sharing. They provide a basic introduction to operating systems for students.
Full Transcript
# **Operating Systems** ## **Lecture 1** **What is the operating system?** - It is a program that acts as an interface between the **user** and the **computer's hardware**. **Objectives of operating systems:** 1. **Make the input convenient to use:** It aims to make user interaction with the...
# **Operating Systems** ## **Lecture 1** **What is the operating system?** - It is a program that acts as an interface between the **user** and the **computer's hardware**. **Objectives of operating systems:** 1. **Make the input convenient to use:** It aims to make user interaction with the computer as simple and intuitive as possible. 2. **Effectively utilize computer resources:** It manages the various hardware components (like memory, CPU, and peripheral devices) efficiently. 3. **Execute user programs and make solving user problems easy:** It allows users to run their programs smoothly and provides tools to address any issues they might face. **Components of a computer system:** 1. **Hardware:** Includes physical components like **memory**, **CPU**, and **input/output devices**. 2. **User:** Represents **people or machines** interacting with the system. 3. **Operating System:** Acts as a **mediator** between the user and the hardware. 4. **Application Programs:** Performs specific **tasks** as defined by the user. **Operating system's role:** - It helps **define ways to solve the user’s problems** by providing a framework for accessing hardware resources and executing application programs. **Characteristics of an operating system:** - It allows users to interact with the computer in a **user-friendly, efficient, and secure** way. - It ensures **good performance** and easy access to system resources. ## **Lecture 2** **Functions of a computer:** 1. **Data Processing:** The computer can process data as instructed by the user. 2. **Data Storage:** Handles storing data, both in **short-term memory (RAM)** and **long-term storage (HDDs)**. 3. **Data Movement:** Transmits data between different components, such as from the **keyboard to memory** or from **memory to output devices**. 4. **Control Unit:** Manages the overall functions of the computer, including **data processing, storage, and movement.** **Computer Structure:** 1. **Central Processing Unit (CPU):** The **brain** of the computer responsible for performing calculations and logical operations. 2. **Main Memory:** Stores **data** for quick access by the CPU. 3. **Input/Output (I/O):** Handles movement of data between the system and external devices. It connects to the computer via **peripheral devices**. 4. **System Interconnection:** Uses **buses** for communication between various components. These buses form the backbone of the system's interconnection. **Components of a CPU:** 1. **Arithmetic and Logic Unit (ALU):** Performs computations and logical operations. 2. **Control Unit:** Coordinates the CPU's functions and controls data flow. 3. **Registers:** Temporary storage areas within the CPU for holding data and instructions. 4. **Bus:** The connection between the CPU and other components, forming the pathways for data and instructions. **Notes:** - The CPU utilizes **buses to communicate** with other components like registers, memory, and peripheral devices. - **Buses** are crucial for transferring data and instructions efficiently. - The **control signal** determines the operation that the circuit performs, and the number of **bits** used in the operation indicates the complexity of the circuit. ## **Lecture 3** **Interrupts:** - An interrupt is an event that **stops the current process** and allows another process to take over. **Causes of interrupts:** 1. **Program:** - A program may encounter an error during execution, causing an interrupt. This includes arithmetic overflows, division by zero, or memory access errors. 2. **Timer:** - A timer interrupt occurs after a specified time interval to allow the operating system to implement time-sharing and ensure efficient allocation of resources. 3. **I/O:** - Device interrupts occur when an I/O device requires attention, such as when a file is finished being read or written. 4. **Hardware/Memory Parity Errors:** - These errors involve inconsistencies in the data stored in memory, which can be detected by parity checking mechanism. **Parity Checking:** - Parity checking uses an extra bit called the parity bit to detect single-bit errors during data transmission or storage. **Even Parity:** The number of ones in the data bits (including the parity bit) is always even. **Odd Parity:** The number of ones in the data bits (including the parity bit) is always odd. **Interrupt Handling with Multiple Tasks:** - The processor handles tasks in a sequence, but when an interrupt occurs, the current task stops. - The processor handles whatever triggered the interrupt (whether a program error, timer event, I/O request, or memory error). - When the interrupt is addressed, the processor resumes the original task. **Interrupt Cycle:** - An interrupt causes the processor to stop and jump to a specific instruction. - The processor saves the context (the address of the interrupted instruction, the CPU's state, and other information) to resume the task later. - The interrupt handling routine is executed. - Once the interrupt is handled, the saved context is restored, and the original task is resumed. **Multiple Interrupts:** - When multiple interrupts occur, the operating system needs to define their priorities. - The priority of an interrupt determines the order in which the interrupts are addressed. **Interrupt Connection:** - Different components can be connected to the CPU via dedicated connections (buses), including memory, I/O devices, and peripheral devices. ## **Lecture 4** **Process States:** - A process can be in different states throughout its execution, including: 1. **New:** - The process has been created and initialized. 2. **Running:** - The process is currently using the CPU to execute its instructions. 3. **Waiting:** - The process is waiting for a resource, such as an I/O operation. 4. **Ready:** The process is ready for execution but currently doesn’t have access to the CPU. 5. **Terminated:** - The process has finished its execution. **Process Control Block (PCB):** - A PCB is a data structure that retains process details like processor state, memory address, I/O status, and priority information. **Process Scheduling:** - The operating system chooses the next process to run (from the ready queue) based on a scheduling algorithm. **Types of Process Scheduling Algorithms:** - **First Come, First Served (FCFS):** Processes are processed in the order they arrive in the queue. - **Shortest Job First (SJF):** The processor always selects the process with the shortest remaining execution time. - **Priority Scheduling:** Processes are scheduled based on their priority. **Scheduling Algorithms and the Ready Queue:** - The ready queue holds processes that are ready to run. - The scheduling algorithm selects processes from the ready queue based on criteria like priority, remaining execution time, or arrival time. **Process Switching:** - Process switching occurs when the CPU switches from one process to another. - It involves saving the current process's context and loading the new process's context, resulting in some overhead in terms of time. **Synchronization:** - It ensures that multiple processes share resources in a controlled and coordinated manner. - Important for cooperating processes to prevent conflicts and data inconsistencies. ## **Lecture 5** **Program Execution:** - A program consists of a sequence of instructions. - This is processed by the CPU using a program counter (PC) that keeps track of the current instruction. - Each instruction goes through two phases: **fetch** and **execute**. **Process Memory:** - A process' memory is broadly divided into the following sections: 1. **Text Section: ** Contains the program code (machine language). 2. **Data Section:** Keeps variables used by the program, including global variables. 3. **Stack:** Temporary storage used to store local variables. 4. **Heap:** Dynamic memory used to store data during program execution. **Process State Transitions:** - A process can transition between various states, including new, running, waiting, ready, and terminated. - These transitions occur when events like creating a process, starting a process, waiting for an I/O operation, or terminating a process happen. **The Role of the Dispatcher:** - The dispatcher selects the process to run from the ready queue. - It decides which process should get the CPU next, and it handles the context switching between different processes. **Resource Sharing:** - Two main approaches to resource sharing: 1. **Shared Resources:** Multiple processes can access the same resources, such as files, memory, or devices. 2. **Separate Resources:** Each process has its own unique resources, minimizing interference between them. **Types of Resource Sharing:** - **Fork():** Creates a child process that is an exact copy of the parent process, including its memory and resources. - **Exec(): ** Replaces the current process with a new process, loading a completely different program. **Process Termination:** - A process can be terminated in the following ways: 1. **Normal Termination:** The process completes its execution and terminates voluntarily. 2. **Abnormal Termination:** The process terminates due to an error, such as a memory access violation or a segmentation fault. 3. **External Termination:** The operating system terminates the process, for example, because it has exceeded its resource limits or is causing problems for other processes. **Zombie Process:** - A zombie process is a terminated process that is still in the process table but no longer running. - The parent process should call `wait()` to reclaim the resources associated with the zombie process. **Orphan Process:** - An orphan process is a process left in the system without its parent process running. - The operating system usually adopts orphaned processes, ensuring their completion, but they are not truly orphaned. **Synchronization Primitives:** - Mechanisms for regulating access to shared resources between multiple processes to avoid data corruption. - Examples include semaphores, mutexes, monitors, and condition variables. **Deadlock:** - Occurs when multiple processes block each other because they are waiting for resources held by each other. - Common causes include insufficient resources, improper use of synchronization mechanisms, and timing issues. **Concepts of Operating System Efficiency:** - **Throughput:** The number of processes completed per unit of time (often considered a measure of the system's overall productivity). - **Response Time:** The time taken for a process to respond to a request. - **Turnaround Time:** The time taken for a process to complete from its arrival to its completion. - **CPU Utilization:** The percentage of CPU time used by processes. **Operating Systems and Kernel Space:** - **Kernel Space:** The memory space where the kernel resides. The kernel manages the system's essential functions. - **User Space:** The memory space where user processes execute. **Key Concepts of Modern Operating Systems:** - **Multithreading:** Allows different threads within a process to run concurrently, increasing efficiency. - **Virtual Memory:** - Extends the physical memory by using disk space. - **File Systems:** Organize and store data on disk. - **Security:** Protection and security mechanisms implemented to safeguard user data and system integrity. - **Network Communication:** Allows systems to communicate with each other across networks. These notes primarily cover basic concepts of Operating Systems like definitions, functions, structure, process states, and memory management. It should be noted that this is not a full and comprehensive documentation of Operating Systems. The content is based on the document/image you provided.