Windows Subsystem for Linux (WSL)

repository·master·Indexed 12 days ago

https://github.com/microsoft/wsl

A compatibility layer for running Linux environments and applications directly on Windows. Includes documentation for the WSL Container API (Microsoft.WSL.Containers), providing native C/C++, C++/WinRT, and C# (.NET 8+) projections to manage and run containers from Windows, as well as MSBuild and CMake integration for automated container image building.

Tokens
85.1K
Snippets
329
Records
464
Agent score
95%

What's inside WSL

  1. Overview of the WSL container API

    master

    The WSL container API allows Windows application developers to integrate Linux containers directly into their application logic. The API follows a hierarchical model of capabilities layered as Session → Container → Process.

    Warning: Preview Status This API is currently in preview. It may undergo breaking changes. It is recommended to use this preview only for feasibility evaluation. Production-grade code should wait until the API reaches general availability (expected Fall 2026).

  2. Overview of Windows Subsystem for Linux (WSL)

    master
    Windows Subsystem for Linux (WSL) allows you to run Linux command-line tools, utilities, and applications unmodified and directly on Windows. It avoids the overhead associated with traditional virtual machines or dual-boot configurations.
  3. Overview of WSL Session APIs

    master

    The WSL Session APIs allow developers to programmatically manage the lifecycle, configuration, and monitoring of WSL sessions. These APIs enable tasks such as creating sessions with specific resource constraints (CPU, memory, VHD), configuring session settings, handling session termination events, and managing crash dump subscriptions.

    Key workflows include:

    1. Session Lifecycle: Initialize settings with WslcInitSessionSettings, create a session with WslcCreateSession, and release it with WslcReleaseSession.
    2. Resource Configuration: Use specific setter functions like WslcSetSessionSettingsCpuCount or WslcSetSessionSettingsMemory to constrain the session environment.
    3. Monitoring and Error Handling: Subscribe to termination events via WslcGetSessionTerminationEvent or register for crash dump callbacks using WslcRegisterSessionCrashDumpCallback.
  4. Use the WSL Container C APIs

    master
    The WSL Container APIs provide a C-based interface for managing Linux containers within the Windows Subsystem for Linux. These APIs allow developers to programmatically create, start, configure, inspect, and delete containers. The workflow typically involves initializing container settings, creating the container, configuring specific attributes (such as networking, volumes, or hostnames), and then managing the container lifecycle (start, stop, delete).
  5. Use the WSL plugin interface via WslPluginApi.h

    master

    The Microsoft.WSL.PluginApi package provides the WslPluginApi.h header file, which defines the interface required to develop plugins for the Windows Subsystem for Linux (WSL). Developers looking to extend WSL functionality should use this header to implement the necessary plugin interfaces.

    For comprehensive documentation on WSL and its capabilities, refer to the official Microsoft Learn documentation: https://learn.microsoft.com/windows/wsl/.

  6. Use WSL Process APIs to manage Linux processes

    master
    The WSL C API provides a set of functions to initialize, configure, and monitor Linux processes running within the Windows Subsystem for Linux. Developers can use these APIs to set up a process with specific working directories, command lines, and environment variables, and then interact with it by retrieving its PID, exit code, or sending signals.
  7. Use wsl.exe as the main command line entrypoint

    master
    The wsl.exe executable serves as the primary command-line interface for interacting with the Windows Subsystem for Linux (WSL). It handles command-line argument parsing, communicates with the wslservice.exe via COM to launch WSL instances, and manages the relay of stdin, stdout, and stderr between the Windows host and the Linux processes.
  8. WSL Container C API Reference Overview

    master

    The WSL container C API is organized into several functional modules. Use these modules to perform the following tasks:

    • Session Management: Create and manage WSL sessions.
    • Container Management: Create and manage containers within a session.
    • Process Management: Start and control processes within containers.
    • Image Management: Manage container images.
    • Storage Management: Manage VHD-backed storage.
    • Platform Management: Check for and install required platform components.
    • System Information: Check installation status and versions.
  9. Understand the role of wslhost.exe

    master

    wslhost.exe is a Windows executable used by WSL for two primary purposes:

    1. Desktop Notifications: It acts as a COM server to display notifications to the user (e.g., regarding WSL updates, configuration errors, or proxy changes).
    2. Background Process Management: It manages the lifecycle of Linux processes when the primary wsl.exe instance terminates, ensuring background processes can continue running and interacting with Windows/the terminal.