/* Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. * * NVIDIA Corporation and its licensors retain all intellectual property * and proprietary rights in and to this software, related documentation * and any modifications thereto. Any use, reproduction, disclosure or * distribution of this software and related documentation without an express * license agreement from NVIDIA Corporation is strictly prohibited. */ #include "wsl_utils.h" bool is_running_in_WSL(void) { static volatile bool verified = false; static volatile bool ret = false; if (!verified) { verified = true; FILE *versionFile = fopen("/proc/version", "r"); if (versionFile != NULL) { char versionInfo[512]; if (fgets(versionInfo, sizeof(versionInfo), versionFile) != NULL) { for (int i=0; versionInfo[i] != '\0'; i++) { versionInfo[i] = tolower((unsigned char)versionInfo[i]); } if (strstr(versionInfo, "microsoft") != NULL) { /* Yes, Running inside WSL */ ret = true; } } fclose(versionFile); } else { printf("ERROR: opening /proc/version failed\n"); } } return ret; }