Operating Systems Lecture 1: Introduction
Introduction to Operating Systems
What is an Operating System?
- An operating system (OS) acts as middleware between user programs and hardware, facilitating the execution of applications like browsers and email clients on computer hardware.
- The OS manages various hardware components such as the CPU, RAM, disk storage, and input/output devices for user programs.
Executable Files and CPU Instructions
- When a program (e.g., a C program) is compiled, it generates an executable file containing instructions specific to the underlying CPU architecture. This process translates high-level code into machine-readable instructions.
- The executable includes both instructions for the CPU and data variables defined in the program. Each CPU has its own instruction set architecture that dictates which commands it can execute.
Program Execution Process
- Upon running a program, its memory is loaded into RAM, including code and data necessary for execution. The CPU uses registers like the program counter (PC) to track which instruction is currently being executed.
- The execution involves fetching instructions from memory, performing computations using operands stored in registers, and writing results back to memory—creating a cycle of interaction between the CPU and RAM.
Role of the Operating System During Execution
- The OS plays a crucial role by managing program memory: it loads executables from disk into RAM for execution while ensuring proper allocation of resources like memory space for each process.
- It also configures the CPU's state by setting values in registers so that processes can run correctly without interference from one another. Additionally, it facilitates communication with other devices such as disks or I/O peripherals.
Process Management by the Operating System
- A key function of an OS is providing process abstraction; when a program runs, it becomes a process managed by the OS which creates an illusion that each process has exclusive access to the CPU despite multiple processes running concurrently.
- The OS time-shares CPU resources among multiple processes while enabling coordination between them—allowing them to communicate or share data effectively during their operation on the system.
Memory Management in Processes
- Each process requires allocated memory containing various elements: compiled code, data variables created by users, stack space for function calls (storing arguments), and heap space for dynamic memory allocation via functions like
malloc.
Understanding Operating Systems
Memory Management in Operating Systems
- Each process operates under the illusion of having exclusive access to memory, using virtual addresses starting from zero. The actual physical memory may be fragmented across different locations.
- The operating system (OS) manages this memory allocation, translating virtual addresses requested by processes into actual physical addresses in RAM. Processes remain unaware of the underlying complexities.
- This virtualization allows processes to function without concern for where their data is physically stored, enhancing usability and efficiency.
Device Management
- The OS also facilitates communication with hardware devices through device drivers, which are specialized pieces of kernel code that understand the specific languages used by various hardware components.
- Device drivers handle instructions sent to devices and manage responses from them, such as interpreting key presses from a keyboard. This abstraction simplifies programming tasks related to hardware interaction.
File System Management
- The OS manages file systems to ensure persistent data storage beyond temporary RAM usage; data saved on disk remains intact even after reboots. This functionality is crucial for long-term data retention and organization.
Design Goals of Operating Systems
Convenience and Abstraction
- A primary goal of an OS is convenience; it abstracts hardware details so users can run programs without needing deep technical knowledge about the underlying systems.
Efficiency
- Operating systems aim for efficient resource utilization, ensuring that CPU time and memory space are maximized while minimizing waste during process execution and storage management.
Isolation
- Security features within an OS protect processes from interfering with one another's memory spaces, maintaining isolation between user programs to prevent accidental or malicious damage. This enhances overall system security and stability.
Evolution of Operating Systems
From Libraries to System Calls
- Initially, operating systems functioned as libraries providing reusable functions for accessing hardware resources; this evolved into more complex interactions via system calls that require higher privilege levels for security purposes.
Increased Complexity