Operating Systems Module 1 - Comprehensive Notes
Operating Systems Module 1 - Comprehensive Notes
Academic Definition: An Operating System is system software that acts as an intermediary between
the computer user and the computer hardware. It is a resource allocator and a control program.
Extensive Description:
The OS has two primary perspectives:
1. Resource Manager (System View): The OS dynamically allocates resources like CPU time,
memory space, file-storage space, and I/O devices to conflicting programs. It ensures efficiency
and fairness.
2. Control Program (User View): It provides a user-friendly environment (abstraction) and controls
the execution of user programs to prevent errors and improper use of the hardware.
Real-Life Example & Software Implementation:
● Real-Life: A government. It doesn't build roads itself, but it provides the environment, rules, and
budget for contractors to build them.
● Implementation: When you run Google Chrome, the OS (like Windows 11) allocates a specific
chunk of RAM to it. If Chrome tries to read memory belonging to your Antivirus, the OS functions
as a control program and blocks it (resulting in a crash or error, protecting the system).
Academic Definition:
Modern operating systems are interrupt-driven and rely on a Dual-Mode Operation to protect the
system from malicious or buggy software. This is achieved via a hardware "Mode Bit" (0 for Kernel, 1 for
User).
Extensive Description:
● User Mode (Mode bit = 1): When the computer is executing a normal application (like MS Word), it
runs in User Mode. It cannot directly access hardware.
● Kernel Mode (Mode bit = 0): Also called supervisor or privileged mode. The OS runs in this mode.
It has total access to all hardware and memory.
● The Transition: If a user program needs hardware access (e.g., reading a file), it generates a Trap
(a software interrupt). The hardware switches the mode bit to 0, transfers control to the OS, the OS
performs the action, changes the bit back to 1, and returns control to the user.
Real-Life Example & Software Implementation:
● Real-Life: A bank customer (User Mode) cannot open the vault. They must fill out a slip and give it
to the Bank Teller (Kernel Mode), who safely gets the money.
● Implementation: When a Java Spring Boot application wants to read a database file from the SSD,
it triggers a trap. The CPU switches from User Mode to Kernel Mode, the Linux Kernel reads the
SSD, and then hands the data back to the Java app in User Mode.
Extensive Description:
Unlike closed-source (proprietary) systems like Microsoft Windows or Apple macOS, open-source
operating systems thrive on community collaboration. Bugs are found and fixed rapidly.
● Advantages: Free, highly secure (because thousands of developers audit the code), and endlessly
customizable.
● Real-World Implementation: Linux is the king of open source. The Linux kernel powers the vast
majority of the internet's backend servers, all Android phones, and Docker containers.
2. System Structures
2.1 Operating System Services
In Simple Terms: These are the amenities provided by the hotel (OS) to the guests (Programs).
Extensive Description:
An OS provides services for the convenience of the programmer:
● Program Execution: Loading a program into RAM and running it.
● I/O Operations: Handling keyboards, mice, screens, and network cards.
● File-System Manipulation: Creating, deleting, reading, and writing files/directories.
● Communications: Allowing Process A to talk to Process B (Inter-Process Communication).
● Error Detection: Catching CPU, memory, or hardware errors to prevent full system crashes.
Types:
1. Command-Line Interface (CLI): Text-based. The user types commands directly. Highly efficient,
uses very little RAM, preferred by backend engineers. (e.g., Bash in Linux, Command Prompt in
Windows).
2. Graphical User Interface (GUI): Visual-based. Uses Windows, Icons, Menus, and a Pointer (WIMP).
User-friendly but consumes more CPU and RAM. (e.g., Windows Desktop, macOS Aqua interface).
In Simple Terms: System Calls are the exact "function calls" or "API calls" that a user program uses to
ask the Operating System for a favor.
Academic Definition: System calls provide the programming interface to the services provided by the
operating system. They act as the bridge between User Space and Kernel Space.
Extensive Description:
Application developers almost never write direct System Calls in assembly language. Instead, they use
an API (Application Programming Interface) like the Win32 API (for Windows) or POSIX API (for
Linux/macOS).
When you call printf() in C or [Link]() in Java, the standard library intercepts this, prepares
the data, and triggers the actual system call (like write()) to the OS.
Extensive Description:
System programs provide a convenient environment for program development and execution.
Categories include:
● File management: Programs to format disks, copy files (e.g., cp, rm in Linux).
● Status information: Task Manager (Windows) or top (Linux) to see RAM/CPU usage.
● File modification: Text editors like Notepad or Vim.
● Programming-language support: Compilers (GCC), Assemblers.
In Simple Terms: How is the OS code organized? Is it one giant messy file of code, or neatly organized
folders?
Types of Structures:
A. Monolithic Kernel
● Description: The entire operating system (file system, memory manager, CPU scheduler, device
drivers) runs as a single, massive program in Kernel Space.
● Advantages: Extremely Fast. Because everything is in one place, components communicate
instantly via direct function calls.
● Disadvantages: Hard to maintain. If a single audio driver crashes, it can bring down the entire OS
(a kernel panic or Blue Screen of Death).
● Implementation: Linux and MS-DOS use monolithic structures. (Though Linux uses "Loadable
Kernel Modules" to make it slightly more flexible).
B. Microkernel
● Description: The OS is stripped down to the bare minimum. The kernel only handles basic CPU
scheduling and memory. Everything else (file system, device drivers) runs in User Space as separate
"Servers".
● Advantages: Highly Secure and Stable. If the file system crashes, only the file system restarts;
the OS survives.
● Disadvantages: Slower. Because components are separated, they must communicate via
message passing through the microkernel, which creates overhead.
● Implementation: QNX (used in BlackBerry and modern car dashboards) and MINIX. macOS
(Darwin) uses a hybrid approach incorporating the Mach microkernel.
C. Layered Approach
● Description: The OS is broken into layers. Layer 0 is the hardware. Layer N is the User Interface.
Layer M can only use the functions of Layer M-1.
● Advantages: Very easy to debug. If layer 2 works but layer 3 fails, you know the bug is in layer 3.
● Disadvantages: Too rigid and slow. An application at Layer 5 might have to pass through 4, 3, 2,
and 1 just to read a disk.
Extensive Description:
A Virtual Machine Monitor (VMM) or Hypervisor creates an illusion that a process has its own
dedicated CPU, memory, and disk.
● Type 1 Hypervisor (Bare-Metal): Runs directly on the hardware. Highly efficient. (e.g., VMware
ESXi, Microsoft Hyper-V). Used in massive Cloud Data Centers like AWS.
● Type 2 Hypervisor (Hosted): Runs as an application inside a host OS (like Windows). It then hosts
guest OSs. (e.g., Oracle VirtualBox, VMware Workstation).
● Implementation: If your company uses microservices, they are likely deploying them on AWS EC2
instances, which are essentially Type 1 Virtual Machines.
Extensive Description:
● Core Dump: If a user application (like your Java backend) crashes due to a bug (like accessing
restricted memory), the OS saves the exact state of that program's memory into a file called a
"core dump". Developers can later open this file to see exactly which line of code caused the crash.
● Crash Dump: If the OS Kernel itself crashes, it dumps its memory state.
● Trace Tools: Tools like strace in Linux. As a backend engineer, if your app is running slowly, you can
use strace to watch every single System Call your app is making to the OS in real-time to find the
bottleneck.