Operating systems | EE433 | Lecture 02

Operating systems | EE433 | Lecture 02

Introduction to Operating Systems

Overview of Operating System Functions

  • The speaker welcomes attendees and introduces the topic of operating systems, emphasizing their importance.
  • Key functions of an operating system include resource management, which involves organizing computer resources like CPU, GPU, network, hard disk, and RAM.
  • Isolation is discussed as a critical function that prevents one program's failure from affecting others on the system.

Resource Management

  • The speaker explains that programmers need to understand how resources are allocated and managed by the OS for reliability.
  • Data reading from hard disks is explained; it occurs in blocks rather than individual bytes to optimize performance.

Kernel: The Core Component of an Operating System

Understanding the Kernel

  • Introduction to the kernel as a fundamental part of the operating system responsible for managing hardware access.
  • The kernel has full permissions over system operations while other programs operate with limited privileges.

Role and Protection Mechanisms

  • Drivers serve as intermediaries between hardware devices and the OS but are not part of the kernel itself.
  • Discussion on how the kernel protects its own integrity by controlling access rights to various resources.

Memory Management in Operating Systems

Memory Structure

  • Explanation of memory organization into instructions, data, metadata (like process information), heap (dynamic memory), and stack (static memory).
  • Variables are stored in different areas: pointers in heap or stack depending on their usage during program execution.

Process Management

  • The kernel manages processes by allocating necessary resources and ensuring they do not interfere with each other’s operations.

Operating Modes: User vs. Kernel Mode

Types of Operation Modes

  • Two operational modes are defined: user mode for regular applications and kernel mode for core OS functions.
  • Only the kernel can execute certain privileged instructions; user applications cannot directly manipulate these without going through system calls.

This structured approach provides a comprehensive overview while allowing easy navigation through key concepts discussed in the transcript.

Understanding Kernel Operations and Memory Protection

Kernel Access and Permissions

  • Discussion on the kernel's ability to access certain areas, highlighting potential vulnerabilities if permissions are mismanaged.
  • Introduction of a programming method that simplifies understanding older techniques before hardware assistance is applied.

Compilation vs. Interpretation

  • Explanation of two methods for running programs: compilers (which generate binary files) and interpreters (which execute code line by line).
  • The interpreter's approach allows for immediate execution of Python code, contrasting with precompiled binaries which run faster but require more setup.

Memory Protection Mechanisms

  • Description of how the kernel can act as an interpreter to protect itself from unauthorized access attempts by processes.
  • Overview of memory protection strategies, emphasizing the need for checks before executing commands to prevent privilege escalation.

Base and Bound Registers

  • Introduction to base and bound registers that define process memory limits; errors occur when processes exceed these boundaries.
  • Explanation of processor exceptions triggered when a process tries to access memory outside its allocated range, transferring control back to the kernel.

Challenges in Memory Management

  • Discussion on limitations related to base and bound registers, including issues with stack and heap management.
  • Identification of fragmentation problems arising from inefficient memory allocation across multiple processes.

Fragmentation Issues

  • Illustration of how fragmentation occurs when multiple programs request varying sizes of memory, leading to unusable gaps in RAM.

Physical vs. Virtual Memory

  • Clarification on physical memory addressing versus virtual memory usage by programmers for easier management without direct hardware concerns.

Timer Interruptions in Process Management

  • Introduction of timer interrupts as a solution for regaining control over CPU resources from runaway processes or infinite loops.
  • Explanation on how timer interrupts allow the kernel to check if other processes need CPU time, ensuring fair resource distribution among all active tasks.

Kernel and Process Management

Overview of Kernel and Process Interaction

  • The kernel operates quickly, transitioning to processes that handle tasks based on a timer. If the process does not complete, it returns control to the kernel.
  • The kernel ensures no other process interferes while executing; it manages multiple background programs effectively.
  • The hardware timer is crucial for the kernel's operation, allowing it to manage time-sensitive tasks efficiently.

Kernel Requests from Hardware

  • The kernel requires three essential commands from hardware: change privilege level, access memory locations, and disable interrupts to maintain uninterrupted execution.
  • When a timer interrupt occurs, the CPU is engaged in processing tasks until a new process arrives.

User and Kernel Execution Transition

  • Understanding when execution shifts between user space and kernel space is vital; this transition occurs during specific events like timer completion or interrupts.
  • Timer interrupts signal the transition from user execution back to the kernel for task management.

Types of Interruptions

Timer Interrupts

  • Timer interrupts are frequent; they allow the CPU to respond quickly to user actions like mouse movements or keyboard inputs.

I/O Device Interrupts

  • Input/Output devices (like keyboards and mice) generate faster interrupts compared to others due to their high-speed data handling capabilities.

Network Interruptions

  • Network packets also trigger interrupts as they approach speeds comparable to CPU performance, necessitating immediate attention from the kernel.

Inter-process Communication

  • Processes can request information from one another through inter-process communication mechanisms managed by the kernel.

Exception Handling in Processes

Process Exceptions

  • A process exception occurs when an error arises during execution (e.g., division by zero), prompting a switch back to the kernel for resolution.

Debugging with Breakpoints

  • Debugging tools utilize breakpoints strategically placed in code execution paths, allowing developers to track down errors effectively.

System Calls

  • System calls enable programs to request services from the kernel directly, such as writing output or accessing system resources.

System Calls and Process Management

Understanding System Calls

  • The speaker discusses the need for system calls to interact with the screen, emphasizing the difference between various types of screens and their functionalities.
  • A distinction is made between different screen types, highlighting that a single screen can handle multiple processes, which simplifies operations.
  • The limitations of system calls are addressed; they cannot directly manipulate certain aspects of the display or input devices.

Role of System Calls in Processes

  • System calls are crucial as they allow programs to request services from the operating system, such as creating or deleting files on a hard disk.
  • The process of sending and receiving data over a network is facilitated through system calls, indicating their importance in networking tasks.

Creating New Processes

  • The creation of new processes involves transitioning from user mode to kernel mode, where specific checks determine if the operation is valid.
  • Kernel registers play a vital role in identifying whether an action originates from user space or kernel space.

Process Switching Mechanism

  • The concept of process switching is introduced; it describes how one process can yield control to another based on timers or interrupts.
  • A detailed explanation follows about how context switching occurs within the kernel when moving between processes.

Handling Interruptions During Execution

  • When an interrupt occurs during execution, state changes are managed by saving current register values and program counters before switching modes.
  • The importance of maintaining accurate states during transitions is emphasized; this ensures that processes can resume correctly after interruptions.

This structured approach provides clarity on key concepts related to system calls and process management while allowing easy navigation through timestamps for further exploration.

Process Creation and Forking in Operating Systems

Understanding Process Creation

  • The discussion begins with the concept of processes, specifically focusing on process IDs (PIDs), permissions, and files that a process can access. It highlights how Windows handles these processes differently compared to Linux and Unix systems.
  • The initial process is described as a parent process that can replicate itself through a mechanism called forking. This allows the creation of child processes that inherit the same permissions as the parent.
  • A key point made is about user-defined permissions; new processes automatically inherit the access rights of their parent processes without needing to request them again from the system.

Security Implications

  • The speaker clarifies that while inherited permissions may seem like a security weakness, they are not inherently dangerous if the original parent process is secure. However, there’s potential risk if malicious code runs within an inherited context.
  • The distinction between user-level processes and kernel-level operations is emphasized, explaining how all user processes start from an initial bootstrapped state managed by the kernel.

Memory Management During Forking

  • When forking occurs, both parent and child share memory initially, which optimizes resource usage. This shared memory model allows faster creation of new processes in Unix compared to Windows.
  • An example program demonstrating forking in C is introduced. It outlines how libraries are included and how fork operations create parallel execution paths for both parent and child processes.

Execution Flow After Forking

  • The mechanics of executing forked programs are discussed further, detailing how each fork results in two distinct execution flows: one for the parent and one for the child.
  • A practical example illustrates how debugging tools can be used to monitor these separate execution paths during development or testing phases.

Practical Applications and Challenges

  • The conversation shifts towards real-world applications such as deep learning projects using PyTorch where multiple threads might complicate data loading due to concurrent executions stemming from forks.
  • Finally, it touches upon common errors encountered when managing multiple threads or forks in programming environments, emphasizing best practices for handling such scenarios effectively.