TECHNOLOGY 

Published on
KembaraXtra-Computer Science - Operating System Software Libraries
I. Introduction
  • An Operating System API is a programmatic interface for interacting with the OS.
  • Software libraries provide the concrete implementation for invoking the OS API.
II. OS Software Libraries
  • Definition: A collection of code included with the OS that implements the OS API.
  • Similarity to Other Libraries: Similar to programming language standard libraries or community-maintained libraries.
  • Format:
    • A file containing machine code.
    • Typically lacks an entry point, so it can't run alone.
    • Exports a set of functions for use by programs.
  • Usage: Programs import (link to) functions from the library to use them.
  • Implementation:
    • Some functions are simple wrappers for kernel system calls.
    • Other functions are fully implemented in user mode code within the library.
    • Some functions implement logic in user mode but also make system calls.
III. Examples
  • Linux: GNU C Library (glibc)
    • Provides access to Linux kernel system calls.
    • Includes the C programming language's standard library functions (some of which don't require system calls).
    • Filename example: libc.so.6 (.so = shared object, 6 = version).
    • Widely used in Linux distributions, so considered part of the standard Linux API.
  • Windows API Libraries
    • Core Libraries:
      • kernel32.dll: Exposes system calls from the NT kernel to user-mode programs.
      • user32.dll: Exposes system calls related to windowing and user interface.
      • gdi32.dll: Exposes system calls related to graphics.
    • .dll Extension: Indicates a dynamic link library (shared library code that a process can load and run).
    • "32" Suffix: Remnant from the 16-bit to 32-bit Windows transition, retained for compatibility. 64-bit Windows includes both 32-bit and 64-bit versions of these files.
IV. Direct System Calls (Alternative, but Not Recommended)
  • Method: Programs can bypass the software library by:
    • Setting values in processor registers.
    • Issuing a processor-specific instruction (e.g., SVC on ARM, SYSCALL on x86).
  • Drawbacks:
    • Requires assembly language programming.
    • Code is not portable across processor architectures.
    • Doesn't provide access to OS API functions not implemented as system calls.
V. Windows Subsystem for Linux (WSL)
  • Challenge: Linux and Windows have different system calls and executable formats, making software incompatible.
  • WSL Solution: Allows running many 64-bit Linux programs on Windows without modification.
  • WSL Versions:
    • WSL1: Intercepts Linux system calls and handles them within the NT kernel.
    • WSL2: Uses a real Linux kernel running in a virtual machine alongside the NT kernel.



Picture
Published on

KembaraXtra-Computer Science - APIs and System Calls

Key Concepts

System Call:

A mechanism for user-mode code to request services from the kernel mode.

Defines a way for applications to interact with the OS involving kernel intervention.

Operating System API (Application Programming Interface):

Describes a way for applications to interact with the OS, regardless of whether kernel-mode code is invoked.

A broader concept than system calls.

Some API functions will make system calls, while others will not.

Relationship between API and System Calls

APIs are not the same as system calls, but they are related.

System calls are a subset of the functionality exposed by an API.

An API can be implemented using system calls, but it can also provide functionality without directly using them.

Examples

Linux

Linux API (Kernel): Can be seen as a specification for using Linux system calls directly.

Android: Uses the Linux kernel, but has its own higher-level programming interfaces called Android Platform APIs.

Windows

Windows NT Kernel: Provides system calls through the Native API.

Generally not used directly by application developers.

Windows API: Acts as a wrapper around the Native API.

Provides a more user-friendly interface for developers.

Windows API Examples

CreateFileW:

Windows API function that creates or opens a file.

A wrapper around the Native API function NtCreateFile.

Requires a system call because it needs kernel-level access to manage files.

PathFindFileNameW:

Windows API function that extracts a filename from a path.

Does not make a system call.

Can be handled entirely in user mode, requiring only virtual memory access.

Summary

Feature System Call Operating System API
Purpose Request kernel-mode services Provide a programmatic interface to the OS
Scope Kernel mode operations Broader; includes both kernel and user mode operations
Implementation Direct interaction with the kernel Can be implemented with or without system calls
Abstraction Level Low-level Higher-level, often more user-friendly
Picture
Published on
KembaraXtra- Computer Science - User Mode Bubble and System Calls
I. User Mode Limitations
  • Definition: Code running in user mode has restricted system access.
  • Capabilities:
    • Read/Write to its own virtual memory.
    • Perform mathematical and logical operations.
    • Control program flow of its own code.
  • Limitations:
    • Cannot access physical memory addresses (including memory-mapped I/O).
    • Cannot directly perform I/O operations (e.g., printing, keyboard input, graphics, sound, network communication, file access).
  • "User Mode Bubble": Analogy representing user mode's isolation from direct hardware interaction.
  • Practical Effect: User mode code can do work but requires assistance to share results.
II. System Calls: Bridging the Gap
  • Definition: A request from user mode code for kernel mode code to perform a privileged operation on its behalf.
  • Purpose: Allows user mode applications to interact with the outside world (perform I/O).
  • Mechanism:
    1. User mode code requests a specific operation (e.g., reading from a file).
    2. The kernel (with device drivers) performs the operation.
    3. The kernel returns the results to the user mode process.
  • Kernel's Role:
  • Acts as an intermediary between user mode code and hardware resources.
  • Provides an abstraction layer, hiding hardware details.
  • Constraints: The kernel enforces security and access control policies (e.g., preventing unauthorized file access).
III. System Call Implementation
  • CPU Instructions: Specific instructions facilitate system calls.
    • ARM: SVC (Supervisor Call).
    • x86: SYSCALL, SYSENTER.
  • System Call Numbers: Each system call is identified by a unique number.
    • Example (Linux ARM): write (file writing) is number 4.
  • Process:
i.Load the system call number into a specific processor register.
ii.Put parameters into other registers.
iii.Execute the system call instruction.
IV. System Calls in Practice
  • Abstraction: Developers typically don't make system calls directly.
  • OS APIs and Standard Libraries: Operating systems and programming languages provide interfaces for system calls (e.g., open, CreateFileA).
  • Transparency: Programmers write code at a higher level and may not be aware of the underlying system calls.
Picture
Published on
KembaraXtra-Conputer Science - API Study Guide
I. Core Concept: Application Programming Interface (API)
  • Definition: A specification that defines how a program interacts with an operating system (OS).
  • Purpose: Allows applications to request services from the OS (e.g., creating files, accessing hardware).
  • Components:
    • Functions: Specific actions an application can request (e.g., open(), CreateFileA(), fopen()).
    • Data Structures: Formats for data passed between the application and the OS.
  • Implementation: APIs are implemented in software libraries that are included with the OS.
II. API vs. User Interface (UI)
  • UI (Shell):
    • Interface for users to interact with the OS (e.g., taskbar, Start menu, command line).
    • Translates user commands into API calls.
  • API:
    • Interface for applications to interact with the OS.
    • Applications call the API directly, bypassing the UI.
III. How APIs Work: Example - Creating a File
  1. User Action (via UI): User clicks "New File" in a graphical shell.
  2. Shell Translation: The UI translates the click into an API call (e.g., a function call to create a file).
  3. API Call: The API function is invoked (e.g., open() in Unix/Linux, CreateFileA() in Windows).
  4. OS Action: The OS code (behind the API) executes the request, creating the file.
  5. Application Action (via API): The application directly invokes open() or CreateFileA() to create a file.
IV. API Examples in Different Languages
  • C:
    • Direct access to OS APIs.
    • Example (Unix/Linux): open("hello.txt", O_WRONLY|O_CREAT);
    • Example (Windows): CreateFileA("hello.txt", GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
  • C (Standard Library):
    • Provides portable functions that work across different OSes.
    • Internally calls the OS-specific API.
    • Example: fopen("hello.txt", "w");
  • Python:
    • Uses a Python interpreter to handle OS-specific API calls.
    • The interpreter translates Python code into the correct OS API calls.
    • Example: open('hello.txt', 'w')
V. API Standards and Implementations
  • POSIX (Portable Operating System Interface):
    • Standard for Unix-like systems (Linux, macOS, etc.).
    • Defines standards for the OS API, shell behavior, and utilities.
  • macOS/iOS:
    • Cocoa (macOS): Apple's API for macOS.
    • Cocoa Touch (iOS): Apple's API for iOS.
  • Android:
    • Android Platform APIs: A set of programming interfaces for Android development.
  • Windows:
    • Win16: Original 16-bit Windows API.
    • Win32: 32-bit Windows API.
    • Win64: 64-bit Windows API.
    • Universal Windows Platform (UWP): Introduced in Windows 10 to provide a consistent API across different Windows devices.
Picture
Published on
KembaraXtra-Computer Science -Virtual Memory
Core Concept
  • Virtual Memory: An abstraction that provides each process with its own large, private address space, isolated from other processes.
Why Use Virtual Memory?
  • Isolation: Prevents processes from accessing or corrupting memory belonging to other processes or the kernel.
  • Abstraction: Simplifies memory management for developers, eliminating fragmentation concerns caused by other processes.
  • Large Address Space: Gives each process the illusion of a large contiguous memory block, even if the physical memory is smaller.
Virtual vs. Physical Addresses
  • Physical Address: Actual hardware memory address. Hidden from user-mode processes.
  • Virtual Address: Address seen by the process. Translated to a physical address by the OS.
Virtual Address Space
  • Each process gets its own virtual address space (e.g., 2GB).
  • Same virtual addresses in different processes map to different physical addresses.
  • Mechanisms exist for processes to intentionally share memory.
  • The entire virtual address space isn't necessarily backed by physical memory initially. Only parts are mapped to physical memory as needed.
Kernel Address Space
  • Separate from user-mode address space.
  • Shared by all code running in kernel mode.
  • Kernel code can access any part of the kernel address space.
Address Space Division (32-bit Systems)
  • 32-bit systems have a 4GB (2^32 bytes) virtual address space.
  • This 4GB is split between kernel and user mode. Common splits:
    • 2GB User / 2GB Kernel
    • 3GB User / 1GB Kernel
Paging
  • Scenario: The total virtual memory requested by processes and the kernel exceeds the available physical RAM.
  • Solution: The OS moves inactive "pages" (blocks) of memory from RAM to secondary storage (e.g., hard drive or SSD).
  • When Needed: If a process tries to access a paged-out memory location, the OS must swap it back into RAM.
  • Tradeoff: Paging allows more virtual memory than physical RAM but introduces a performance penalty due to slower secondary storage access.
64-bit Systems
  • Potential: Huge address spaces (2^64 bytes).
  • Reality: Current implementations use fewer bits (e.g., 48-bit addresses, yielding 256TB of virtual address space).
  • Still vastly larger than 32-bit address spaces.



Picture
Published on
KembaraXtra-Computer Science -Threads
1. Introduction to Threads
  • Default Program Execution: Programs typically execute instructions sequentially, handling one task at a time.
  • Need for Parallelism: Threads enable programs to perform multiple tasks concurrently (in parallel). Example: A program performing a long calculation while simultaneously updating the user interface (e.g., a progress bar).
  • Definition of a Thread: A thread is a schedulable unit of execution within a process, allowing for parallel execution of tasks. It can execute any program code loaded within that process.
2. Thread Characteristics
  • Task Focus: The code run by a thread typically encompasses a specific task the program aims to accomplish.
  • Shared Resources: Threads within a process share the same address space, code, and other resources.
  • Thread Creation: A process starts with one thread and can create additional threads as needed for parallel task handling.
  • Thread ID (TID): Each thread has a unique identifier.
3. Threads in Windows vs. Linux
  • Windows: Threads and processes are distinct object types. A process acts as a container for threads.
  • Linux: Both processes and threads are represented using a single data type. A group of threads sharing an address space and a common process identifier is considered a process. There is no separate process type.
4. Linux Thread and Process Identifiers
  • User Mode: Processes have a Process ID (PID), and threads have a Thread ID (TID).
  • Kernel Mode: The Linux kernel refers to a thread's ID as a PID and a process's ID as a thread group identifier (TGID).
5. Parallel Execution
  • The Illusion of Parallelism: Although threads are said to run in parallel, the actual simultaneous execution depends on the number of processor cores.
  • Processor Cores: Each processor core can execute only one thread at a time. The number of cores determines how many threads can run concurrently.
6. Physical vs. Logical Cores
  • Physical Core: A hardware implementation of a core within a CPU.
  • Logical Core: The ability of a single physical core to run multiple threads simultaneously (one thread per logical core). Intel's hyper-threading is an example. Logical cores do not achieve the full parallelism of physical cores.
7. The Role of the Operating System Scheduler
  • Scheduling: The operating system uses a scheduler, a software component, to manage thread execution.
  • Time Allocation: The scheduler allocates short periods of time (quantum) for each thread to run before suspending it to allow other threads to execute.
  • Transparency: This scheduling process is mostly hidden from the thread's code, giving the illusion of continuous parallel execution.
  • Developer Perspective: Developers write multithreaded applications as if all threads are running continuously in parallel.



Picture
Published on
KembaraXtra-Case Law-Processes
What is a Process?
  • Definition: A process is a running instance of a program. It's the OS's way of executing a program.
  • Analogy: Think of a program as a recipe, and a process as someone actually following that recipe to bake a cake.
  • Location: Processes operate in user mode.
Key Components of a Process:
  • Container: A process acts as a container for a program's execution.
  • Private Virtual Memory Address Space: A dedicated memory space for the process (more on this later).
  • Program Code: A copy of the program's instructions loaded into the process's memory.
  • State Information: Data about the current status of the process.
Process Characteristics:
  • Multiple Instances: You can run the same program multiple times, creating a separate process for each instance.
  • Process ID (PID): A unique numerical identifier assigned to each process by the OS.
Process Relationships (Parent-Child):
  • Parent Process: The process that starts (creates) another process.
  • Child Process: The process created by a parent process.
  • Process Tree: The hierarchical relationship between processes, with parent processes branching out to child processes.
  • Orphan Process: A child process whose parent has terminated before the child.
    • Windows Behavior: The orphaned process remains parentless.
    • Linux Behavior: The init process (the first user-mode process) typically adopts the orphaned process.
Tools for Viewing Processes:
  • Linux:
    • pstree utility: Displays the process tree in a textual format.
      • Child threads shown with curly braces.
  • Windows:
    • Process Explorer (Microsoft): A GUI-based tool providing a comprehensive view of running processes.

KembaraXtra-Computer Science -Threads
1. Introduction to Threads
  • Default Program Execution: Programs typically execute instructions sequentially, handling one task at a time.
  • Need for Parallelism: Threads enable programs to perform multiple tasks concurrently (in parallel). Example: A program performing a long calculation while simultaneously updating the user interface (e.g., a progress bar).
  • Definition of a Thread: A thread is a schedulable unit of execution within a process, allowing for parallel execution of tasks. It can execute any program code loaded within that process.
2. Thread Characteristics
  • Task Focus: The code run by a thread typically encompasses a specific task the program aims to accomplish.
  • Shared Resources: Threads within a process share the same address space, code, and other resources.
  • Thread Creation: A process starts with one thread and can create additional threads as needed for parallel task handling.
  • Thread ID (TID): Each thread has a unique identifier.
3. Threads in Windows vs. Linux
  • Windows: Threads and processes are distinct object types. A process acts as a container for threads.
  • Linux: Both processes and threads are represented using a single data type. A group of threads sharing an address space and a common process identifier is considered a process. There is no separate process type.
4. Linux Thread and Process Identifiers
  • User Mode: Processes have a Process ID (PID), and threads have a Thread ID (TID).
  • Kernel Mode: The Linux kernel refers to a thread's ID as a PID and a process's ID as a thread group identifier (TGID).
5. Parallel Execution
  • The Illusion of Parallelism: Although threads are said to run in parallel, the actual simultaneous execution depends on the number of processor cores.
  • Processor Cores: Each processor core can execute only one thread at a time. The number of cores determines how many threads can run concurrently.
6. Physical vs. Logical Cores
  • Physical Core: A hardware implementation of a core within a CPU.
  • Logical Core: The ability of a single physical core to run multiple threads simultaneously (one thread per logical core). Intel's hyper-threading is an example. Logical cores do not achieve the full parallelism of physical cores.
7. The Role of the Operating System Scheduler
  • Scheduling: The operating system uses a scheduler, a software component, to manage thread execution.
  • Time Allocation: The scheduler allocates short periods of time (quantum) for each thread to run before suspending it to allow other threads to execute.
  • Transparency: This scheduling process is mostly hidden from the thread's code, giving the illusion of continuous parallel execution.
  • Developer Perspective: Developers write multithreaded applications as if all threads are running continuously in parallel.
Picture
Published on
KembaraXtra- Computer Science-Kernel Mode and User Mode
I. Core Concept: Privilege Levels
  • Definition: A CPU capability that grants the operating system special rights while restricting other code. It's a way to control what different parts of the software can do.
  • Purpose: Ensures programs behave well, prevents interference between programs and the OS, restricts direct hardware access, and protects system files.
II. Two Main Privilege Levels
  • Kernel Mode (Supervisor Mode):
    • Privileges: Highest level of privilege; full access to the system (memory, I/O devices, special CPU instructions).
    • Trust: Code running in kernel mode is trusted.
    • Components: Kernel, device drivers, and key OS components.
  • User Mode:
    • Privileges: Lower level of privilege; limited access.
    • Trust: Code running in user mode is untrusted.
    • Components: Most applications.
III. Why Use Kernel Mode?
  • Ensuring Trust: Only trusted code runs in kernel mode.
  • Control: Allows the operating system to enforce rules and prevent user mode code from misbehaving.
  • Security: Prevents direct access to hardware and critical system resources by user applications.
IV. Kernel Mode Components in Windows
  • Key Components:
    • Kernel & Executive: Core kernel-mode functionalities (often discussed together). Stored in ntoskrnl.exe.
    • Hardware Abstraction Layer (HAL): Isolates the kernel, executive, and device drivers from hardware differences.
    • Windowing and Graphics System (win32k): Provides graphics drawing and user interface interaction capabilities.
Picture
Published on

Operating System Families: Study Guide

I. Overview

Two Dominant Families:

- Unix-like operating systems
- Microsoft Windows

II. Unix-like Operating Systems

Characteristics: Behave like the original Unix OS.

Examples: Linux, macOS, iOS, Android.

History of Unix:
- Developed at Bell Labs in the 1960s.
- Originally for PDP-7 minicomputer, later ported.
- Rewritten in C, enabling portability.
- Supports multiple users, multitasking, and hierarchical directory structure.
- Strong command line shell with standard tools.

Linux:
- Kernel developed by Linus Torvalds.
- Unix-like but doesn't contain Unix source code.
- Open source.
- Bundled with other software to form a Linux distribution.
- Often includes components from the GNU project.

GNU:
- Recursive acronym for "GNU's Not Unix."
- A project to create a free Unix-like OS.
- Complements Linux: Linux provides the kernel, GNU provides other tools (shell, libraries).
- "Linux" often refers to the combination of the Linux kernel and GNU software.

Usage of Linux:
- Common on servers, embedded systems, and with software developers.
- Android OS is based on the Linux kernel.
- Raspberry Pi OS is a Linux distribution.

III. Microsoft Windows

Dominance: Dominant OS on personal computers (desktops, laptops). Strong presence on servers (Windows Server).

Unique History: Doesn't originate from Unix. Early versions based on MS-DOS.

OS/2:
- Joint project with IBM to succeed MS-DOS.
- Microsoft and IBM diverged; IBM took over OS/2.
- Microsoft shifted focus to Windows NT.

Windows NT:
- New kernel, unlike DOS-based Windows.
- Designed to be portable, compatible, support multiple users, and provide security/reliability.
- Led by Dave Cutler (formerly DEC).
- Elements of NT kernel based on DEC's VMS OS.

Evolution of Windows:
- Early Windows NT positioned for business use, coexisting with consumer Windows.
- Shared UI and programming interface.
- Windows XP (2001) brought the NT kernel to consumer Windows.
- All versions of desktop and server Windows since XP are built on the NT kernel.

IV. Common Operating Systems and Their Families

OS or Device Family Notes
Android Unix-like Uses Linux kernel but has a different user experience and programming interfaces.
iOS Unix-like Based on Darwin OS; user experience and programming interface differ from typical Unix.
macOS Unix-like Based on Darwin OS.
PlayStation 4 Unix-like Based on FreeBSD kernel.
Raspberry Pi OS Unix-like Linux distribution.
Ubuntu Unix-like Linux distribution.
Windows 10 Windows Uses the Windows NT kernel.
Xbox One Windows OS uses the Windows NT kernel.

V. Key Terms

Kernel: The core of an operating system.

Distribution: A specific release of an OS, usually referring to Linux.

Open Source: Software with freely available source code.

Command Line Interface (CLI): A text-based interface for interacting with an OS.

Published on
KembaraXtra-Computer Science - Operating Systems Overview
I. Introduction to Operating Systems (OS)
  • Definition: Software that communicates with computer hardware, providing an environment for program execution.
  • Purpose:
    • Abstracts hardware details, allowing developers to focus on application logic.
    • Provides a common set of services for applications.
    • Manages hardware resources (memory, I/O devices, etc.).
    • Enables multitasking (running multiple programs concurrently).
    • Enforces isolation between programs and the OS, as well as user access control.
  • Role as a Layer: Acts as an intermediary between hardware and applications.
    • Hides hardware complexity.
    • Offers a consistent programming model.
    • Facilitates software development across diverse hardware.
II. Key Components of an Operating System
  • Two Major Categories:
    1. Kernel: The core of the OS.
    2. Everything Else: Non-kernel components that provide usability.
  • The Kernel:
  • Responsibilities:
    • Memory management.
    • Device I/O facilitation.
    • Providing system services to applications.
    • Enabling multitasking and resource sharing.
  • Limitation: By itself, it doesn't provide a user interface.
  • Shell:
  • Definition: User interface for interacting with the kernel.
  • Types:
    • Command Line Interface (CLI): e.g., Bash shell (Linux/Unix).
    • Graphical User Interface (GUI): e.g., Windows shell (desktop, Start menu, taskbar, File Explorer).
  • Daemons/Services:
  • Definition: Background processes that provide OS capabilities.
  • Examples:
    • Task Scheduler (Windows).
    • cron (Unix/Linux) - Scheduling programs to run at specific times.
  • Software Libraries:
  • Purpose: Provide common code for applications and OS components (shell, services) to use.
  • Benefit: Promotes code reuse and simplifies development.
  • Device Drivers:
  • Definition: Software designed to interact with specific hardware devices.
  • Role: Bridge the gap between the kernel and diverse hardware.
  • OS Inclusion: OSes include drivers for common hardware and mechanisms for installing additional drivers.
  • Utilities:
  • Definition: Basic applications included with most OSes (text editor, calculator, web browser).
  • Classification: Arguably not core OS components, but often bundled for convenience.
III. Component Relationships
  • Foundation: Kernel and device drivers directly interact with hardware.
  • Libraries: Provide functionality that both OS components (shell, services, utilities) and applications build upon.
  • Layered Architecture (from bottom to top):
    1. Hardware
    2. Kernel & Device Drivers
    3. Libraries
    4. Shell, Services, Utilities, Applications
Picture