Windows Operating System basics -1

Understanding Windows Operating System Architecture: A Simple Guide

The Windows operating system is a powerful and versatile platform used in everything from personal laptops to large data centers. Its architecture is designed to ensure stability, security, and efficiency.

At its core, Windows is divided into two major components:

1. User Mode (Safe Zone for Applications)

This is where all user applications (like browsers, games, and software) run.

  • Lower privilege: Prevents direct access to system resources.

  • Isolated memory space: Each app runs in its own memory space, preventing one program from interfering with another.

  • APIs (Application Programming Interfaces): Allow apps to request access to system resources safely.

2. Kernel Mode (The Brain of the System)

This is where the core system processes operate, managing CPU, memory, and hardware.

  • Highest privilege: Has full control over the system.

  • Manages system resources: Controls memory, CPU scheduling, and device interactions.

  • Shared memory space: All kernel processes run in the same memory space for efficiency.

Why This Separation Matters

  • Security: Prevents user applications from directly modifying system settings.

  • Stability: A crashing app in User Mode won’t bring down the whole system.

  • Performance: Kernel processes run more efficiently by sharing resources.

How Windows Starts Up

When Windows boots up, it initializes both modes using the Session Manager (Smss.exe). You can check the system’s operating mode in the Windows registry at:
πŸ“‚ HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\SubSystems

By keeping these two components separate, Windows ensures a balance between security, stability, and performance.

Understanding User Mode in Windows: A Simple Guide

In Windows, processes run in two modes: User Mode (for apps and user processes) and Kernel Mode (for core system processes). Let’s focus on User Mode, where all user-initiated programs and services operate.


What is User Mode?

  • User Mode is where apps and user-specific processes run.

  • Each process gets its own memory space, preventing interference between applications.

  • Processes run with lower privileges, meaning they can’t directly access system resources.

  • If a process needs system resources (like writing to a file), it makes a controlled request via APIs.


Types of User Mode Processes

Windows User Mode processes fall into four categories:

1. Non-Service Processes (Essential System Functions)

These are background processes that support user access to the system but are not full-fledged services.
πŸ›  Examples:

  • Login services (handling user sign-ins)

  • Session Manager (Smss.exe) (manages user sessions)

2. Service Processes (User-Dependent Services)

These are services that run based on user needs, unlike system services that run continuously.
πŸ”„ Examples:

  • Task Scheduler (manages scheduled tasks)

  • Print Spooler (handles print jobs)

3. User Applications (Programs You Run)

This includes any app started by the user, like browsers, media players, or word processors.
πŸ“‚ Examples:

  • Google Chrome

  • Microsoft Word

4. Operating System Environment Support (Compatibility Layer)

Windows originally supported multiple environments, like OS/2 and POSIX, for running different software.

  • Today, it uses the Subsystem for UNIX-based Applications (SUA) for running Unix/Linux apps.

How User Mode Interacts with Kernel Mode

User Mode processes can’t directly access system resources (like files or networks). Instead, they:
βœ… Request access via system APIs
πŸ”„ The system switches to Kernel Mode to handle the request
πŸ” Once completed, it switches back to User Mode

This ensures security, stability, and controlled access to system resources.


Final Thoughts

User Mode is the safe zone where applications run without interfering with critical system functions. By isolating user processes and controlling resource access, Windows maintains a secure and stable environment.

Understanding Kernel Mode in Windows: A Simple Guide

While User Mode is where apps and user processes run, Kernel Mode is the core of the Windows operating system. This is where critical system processes operate with full control over hardware and memory.


What is Kernel Mode?

  • Kernel Mode processes share the same memory space, unlike User Mode, where each process has its own memory.

  • This allows for faster and more efficient operations.

  • However, a bug in Kernel Mode can crash the entire system because all critical processes are interconnected.

  • To prevent malicious or faulty code, Windows enforces Kernel Mode Code Signingβ€”meaning system drivers must be digitally signed by a trusted authority.


Key Components of Kernel Mode

Windows Kernel Mode consists of several important subsystems:

1. Kernel Executive (OS Core Functions)

πŸ›  Handles essential system operations, such as:

  • Input/Output (I/O)

  • Networking

  • Memory management

2. Kernel (System Management)

πŸ”„ Manages low-level operations, including:

  • Thread scheduling (determines which process runs next)

  • Handling system interrupts (responding to hardware and software requests)

3. Device Drivers (Hardware Communication)

πŸ”Œ Translates software requests into hardware actions, such as:

  • Reading from a hard drive

  • Sending output to a printer

  • Processing keyboard and mouse inputs

4. Hardware Abstraction Layer (HAL) (Hardware Compatibility)

πŸ–₯ Bridges the gap between Windows and hardware by:

  • Standardizing how Windows interacts with different motherboards and processors

  • Allowing Windows to run on different hardware without modifications

5. Window Management & Graphics Subsystem (GUI Management)

🎨 Handles Windows interface graphics and display functions, ensuring:

  • Smooth rendering of UI elements

  • Efficient screen drawing and user input processing


Important Kernel Mode Files in Windows

These system files are the backbone of Windows Kernel Mode:

πŸ“Œ Ntoskrnl.exe β†’ The Windows executive and kernel
πŸ“Œ Hal.dll β†’ The HAL module (manages hardware interaction)
πŸ“Œ Win32k.sys β†’ Manages Windows display and user input (keyboard/mouse)
πŸ“Œ Ntdll.dll β†’ System service dispatcher (handles system calls)
πŸ“Œ Kernel32.dll β†’ Windows subsystem core (provides OS functions to apps)
πŸ“Œ Advapi32.dll β†’ Security & access control functions
πŸ“Œ User32.dll β†’ Manages user interface elements (e.g., buttons, menus)
πŸ“Œ Gdi32.dll β†’ Handles graphical operations


Why Does Kernel Mode Matter?

  • It’s the β€œbrain” of Windows, managing everything from hardware communication to memory and system security.

  • Crashes in Kernel Mode can bring down the whole system, unlike User Mode crashes, which only affect a single app.

  • To protect system integrity, Windows restricts direct access to Kernel Mode, requiring processes to make controlled system calls.


Final Thoughts

Kernel Mode is what keeps Windows running efficiently, handling critical tasks like hardware communication, memory management, and process execution. By enforcing strict security and code signing, Windows ensures that only trusted code runs in this highly privileged space.

Understanding Windows Processes, Threads, and Handles: A Beginner-Friendly Guide

In Windows, every application you run consists of processes, threads, and handles. These elements define how programs execute, how they utilize system resources, and how Windows manages them efficiently.


What is a Process?

A process is simply an instance of a running program. Every time you open an application, Windows creates a new process to manage it.

Each process has essential characteristics:
βœ… Virtual Address Space β†’ Memory allocated for the process
βœ… Executable Code β†’ The actual program instructions
βœ… Handles to System Objects β†’ Access to files, devices, and other resources
βœ… Security Context β†’ Permissions and user credentials
βœ… Unique Process ID β†’ A unique identifier assigned by Windows
βœ… Environment Variables β†’ Custom settings affecting the process
βœ… Priority Class β†’ Determines how much CPU time the process gets
βœ… Working Set Sizes β†’ Minimum and maximum memory usage
βœ… Threads β†’ The units of execution

πŸ’‘ Every process starts with at least one thread, known as the primary thread, but can create more threads as needed.


What is a Thread?

A thread is the smallest unit of execution in Windows. It represents an individual task within a process.

Key Features of Threads:

πŸ”Ή Each process can have multiple threads.
πŸ”Ή Threads share the same memory space and resources within a process.
πŸ”Ή Each thread has its own:

  • Exception handlers (to handle errors)

  • Scheduling priority (to determine execution order)

  • Thread Local Storage (TLS) (for storing thread-specific data)

  • Unique Thread ID

  • Thread Context (registers, stack, execution state)

Why Use Multiple Threads?

πŸ–₯️ Better Performance β†’ Multithreading allows programs to execute tasks concurrently, improving efficiency.
⚑ Faster Response Time β†’ Apps can stay responsive even when performing background tasks.
πŸ”„ Preemptive Multitasking β†’ Windows schedules multiple threads, creating the illusion of simultaneous execution.

πŸ’‘ On multiprocessor systems, Windows truly executes multiple threads in parallel, assigning them to different CPU cores.


What are Handles?

A handle is a special identifier that allows a process to interact with a system resource (e.g., files, threads, images).

Why Handles Matter?

πŸ”’ Security β†’ Processes can’t directly access system resources; they must request handles.
πŸ“‚ Resource Management β†’ Windows tracks resources using handles, preventing unauthorized access.
πŸ”§ Object Control β†’ Every system object (files, threads, etc.) has an entry in an internal table that maps handles to resources.

πŸ’‘ Without handles, a program cannot read, write, or modify system resources directly.


How Windows Manages Processes & Threads

🟒 Each application runs as a separate process.
🟒 Processes can have multiple threads, executing tasks in parallel.
🟒 Windows handles thread scheduling automatically, based on priority and system load.
🟒 System resources are protected using handles, ensuring security and stability.


Final Thoughts

Understanding Windows processes, threads, and handles is essential for optimizing performance, debugging applications, and ensuring efficient resource usage. Whether you're developing software or troubleshooting system issues, knowing how Windows manages execution will give you an edge! πŸš€

Β