These examples for C, C++, Fortran, and Python show how to detect if a program is running under Windows Subsystem for Linux (WSL).
There is one header file "is_wsl.h" that works for C and C++ under include/.
The Python example has a function "wsl_available()" that checks if WSL is available and working on the computer.
cmake -Bbuild
cmake --build build
Optionally, run the examples:
ctest --test-dir build
The method is to check the kernel name string to see if it contains:
- "-Microsoft " (WSLv1)
- "microsoft-standard-WSL" (WSLv2)
Manually see relevant info:
# from Windows PowerShell or Command Prompt
wsl.exe -l -v
from WSL Terminal:
uname -a
Our GitHub Workflow gives an example of WSLv1 on GitHub Actions.
There is not currently a way to run WSLv2 directly on GitHub Actions or AppVeyor. One can run WSLv2 in CI using an image or a custom GitHub Action.