Skip to content

scivision/detect-windows-subsystem-for-linux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Check if running in Windows Subsystem for Linux

cmake

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.

Build C, C++, Fortran examples

cmake -Bbuild
cmake --build build

Optionally, run the examples:

ctest --test-dir build

Heuristic

The method is to check the kernel name string to see if it contains:

  • "-Microsoft " (WSLv1)
  • "microsoft-standard-WSL" (WSLv2)

Human check

Manually see relevant info:

# from Windows PowerShell or Command Prompt
wsl.exe -l -v

from WSL Terminal:

uname -a

CI Notes

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.

About

Detect WSL--also works on non-Windows computers (always false)

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

No packages published