Unit 2 - Notes
CSE111
Unit 2: Operating System
1. Operating System and its Architecture
Definition
An Operating System (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. It acts as an intermediary (interface) between the computer user and the computer hardware.
Architecture of an Operating System
The architecture of an OS typically consists of layers that isolate the user from the hardware complexity.
- Hardware Layer: The physical components (CPU, RAM, Disk, I/O devices).
- Kernel: The core component of the OS that interacts directly with the hardware.
- System Call Interface (Shell): A set of functions that allow user programs to request services from the kernel.
- User Space (Application Layer): Where user applications (browsers, text editors) run.
Visual Flow:
User Application System Call Kernel Hardware
2. The Kernel and Types of Kernels
The Kernel
The kernel is the central core of the operating system. It has complete control over everything in the system. It is the first program loaded on start-up (after the bootloader) and handles the rest of the startup as well as input/output requests from software.
Types of Kernels
A. Monolithic Kernel
All operating system services (file management, memory management, device drivers) run in the same address space as the kernel.
- Pros: High performance because there is little overhead in communication between subsystems.
- Cons: If one service crashes (e.g., a driver), the entire system can crash.
- Examples: Linux, MS-DOS, Unix.
B. Microkernel
Only the essential services (scheduling, basic IPC) are kept in the kernel. Other services like file systems and device drivers run in user space.
- Pros: High stability and security; if a service fails, the kernel remains unaffected. Easy to extend.
- Cons: slower performance due to context switching and message passing between user space and kernel space.
- Examples: Minix, QNX, L4.
C. Hybrid Kernel
A combination of both. It runs some services in the kernel space for performance (like monolithic) and others in user space for stability (like microkernel).
- Examples: Windows NT kernel (Windows 10/11), macOS (XNU).
D. Exo-Kernel
A minimal kernel that multiplexes hardware resources but leaves the management (abstraction) to the application. Extremely rare, used mostly in research.
3. The Bootloader
Definition
A Bootloader is a small program responsible for booting a computer. It is stored in the ROM or the Master Boot Record (MBR) of the hard drive.
The Boot Process
- BIOS/UEFI: Upon powering on, the hardware runs a Power-On Self-Test (POST).
- Locate Bootloader: The BIOS looks for a boot device and loads the bootloader into RAM.
- Load Kernel: The bootloader locates the Operating System kernel on the disk and loads it into memory.
- Transfer Control: The bootloader passes control of the CPU to the OS kernel.
Examples: GRUB (Linux), Windows Boot Manager (Windows).
4. Functions of Operating System
The OS performs five primary functions:
-
Process Management:
- Creating and deleting processes.
- Scheduling processes (deciding which program uses the CPU).
- Synchronization and Deadlock handling.
-
Memory Management:
- Allocating and deallocating memory to programs.
- Keeping track of which parts of memory are in use.
- Virtual Memory: Using hard disk space to simulate extra RAM.
-
File Management:
- Creating, deleting, reading, and writing files.
- Organizing files into directories.
- Mapping files onto secondary storage (disk).
-
Device Management (I/O Management):
- Managing device drivers.
- Handling buffers and caches for I/O devices (Keyboards, Printers, Disks).
-
Security and Protection:
- Authentication: Verifying user identity (passwords).
- Authorization: Controlling access to files and resources.
- Protection against malware and unauthorized access.
5. Types of Operating Systems
-
Batch Operating System:
- Users do not interact directly with the computer. Jobs are prepared offline (punch cards) and submitted. Similar jobs are grouped (batched) for execution.
- Example: IBM OS/360 (Legacy).
-
Time-Sharing / Multitasking OS:
- Allows multiple users (or programs) to share the computer resources simultaneously. The CPU switches rapidly between tasks (context switching).
- Example: Windows, macOS, Linux.
-
Distributed Operating System:
- Manages a group of distinct computers and makes them appear to be a single computer. Computation is distributed among several physical processors.
- Example: LOCUS.
-
Network Operating System (NOS):
- Runs on a server and provides the capability to manage data, users, groups, security, and other networking functions.
- Example: Windows Server, Red Hat Enterprise Linux.
-
Real-Time Operating System (RTOS):
- Used when rigid time requirements are placed on the operation of a processor or the flow of data.
- Hard RTOS: Critical tasks must be completed on time (e.g., Airbag systems).
- Soft RTOS: Critical tasks get priority, but missed deadlines aren't catastrophic (e.g., Video streaming).
- Example: VxWorks, RTLinux.
6. Directory Hierarchy
A file system organizes data on a storage device. The structure is usually hierarchical (Tree Structure).
- Root Directory: The top-level directory that contains all other directories and files.
- Windows: Represented as
C:\(Drive letter). - Unix/Linux: Represented as
/(Forward slash).
- Windows: Represented as
- Parent and Child: A directory inside another is a "child" or "subdirectory".
- Path: The location of a file.
- Absolute Path: Full address from root (e.g.,
C:\Users\Docs\file.txt). - Relative Path: Location relative to the current working directory.
- Absolute Path: Full address from root (e.g.,
Structure Visualization:
/ (Root)
├── bin (Binary executables)
├── home (User files)
│ ├── User1
│ │ ├── Documents
│ │ └── Pictures
│ └── User2
└── etc (System configuration)
7. Computer Languages
Computer languages are divided into three generations based on their abstraction level.
A. Machine Language (Low-Level)
- Definition: The native language of the computer, consisting entirely of binary digits (0s and 1s).
- Characteristics:
- Directly executed by the CPU.
- Hardware dependent (code for Intel CPUs won't work on ARM).
- Extremely difficult for humans to read or write.
- Example:
10110000 01100001(Moves hex value 61 into a register).
B. Assembly Language (Low-Level)
- Definition: Uses Mnemonics (symbolic codes) instead of binary codes to represent machine instructions.
- Characteristics:
- Easier than machine language but still requires hardware knowledge.
- Requires an Assembler to translate into machine code.
- One-to-one correspondence with machine instructions.
- Example:
MOV AL, 61h(Move 61 hex into AL register).
C. High-Level Language (HLL)
- Definition: Languages designed to be easy for humans to read and write. They use English-like statements and mathematical notation.
- Characteristics:
- Portable (Hardware independent).
- Requires a Compiler or Interpreter to translate.
- Focuses on logic rather than hardware architecture.
- Examples: C++, Java, Python, C#.
8. Language Translators
Since computers only understand Machine Code, other languages must be translated.
Assembler
- Input: Assembly Language code.
- Output: Machine Code (Object Code).
- Function: Translates mnemonics directly to binary.
Compiler
- Input: High-Level Language source code.
- Output: Machine Code (Executable file).
- Process: Scans the entire program at once and translates it. It generates an error report if syntax errors are found.
- Pros: Fast execution time (once compiled). Code is hidden from the user.
- Examples: C, C++, Swift.
Interpreter
- Input: High-Level Language source code.
- Process: Translates and executes the program line-by-line. It stops immediately when an error is found.
- Pros: Easier debugging; platform independence.
- Cons: Slower execution time compared to compiled code.
- Examples: Python, JavaScript, PHP.
| Feature | Compiler | Interpreter |
|---|---|---|
| Translation | Whole program at once | Line by line |
| Errors | Reported after scanning whole code | Stops at first error |
| Execution Speed | Faster | Slower |
| Output | Generates an executable file (e.g., .exe) | Does not generate a standalone file |
9. Steps in Development of a Program
Developing software involves a systematic lifecycle:
- Problem Definition: Understanding what the program needs to achieve.
- Algorithm/Flowchart Design: Creating the logic steps (pseudocode) or visual representation (flowchart) of the solution.
- Coding: Writing the actual source code in a High-Level Language.
- Compilation: Translating the code into machine language.
- Debugging/Testing: Finding and fixing logical or syntax errors.
- Documentation: creating user manuals and technical comments.
- Maintenance: Updating the program after release.
10. Compilation and Execution Process
This explains what happens technically when you click "Run" on a C or C++ program.
- Preprocessing: The Preprocessor handles directives (lines starting with
#like#include). It expands macros and includes library files. - Compilation: The Compiler translates the preprocessed code into Assembly Code.
- Assembly: The Assembler converts assembly code into Object Code (Machine code usually ending in
.oor.obj). At this stage, the code is machine-readable but not yet executable (links are missing). - Linking: The Linker combines the object code with standard library files (like
stdio.himplementations) to create a single Executable File (e.g.,.exeor.out). - Loading: The Loader (part of the OS) loads the executable file from the hard disk into the RAM.
- Execution: The CPU fetches instructions from RAM and executes them.