

Please criticize my solution, I am definitely not a Windows guy, I am on the Linux side, so had to learn things digging into this. It looks like this post/question has many views, but no up2date solutions, so I post it here. I ran into the same problem: Windows 10 wsl2 Ubuntu Linux isn't working in background, if I have wsl console session closed. It's currently the second-most-voted-for request, and is "on the backlog". For something explicitly intended as a developer tool, it sometimes feels like WSL is only usable as a plaything and its users can't be trusted to know what they're doing.Īnyhow, if you want this fixed, vote for Consider enabling cron jobs, daemons and background tasks on the UserVoice page. The justification for this was "to conserve resources", which is absurd on several different levels but most notably because, dammit, my computer has those resources and they are there to be used! If I want a process to run, it should run if I don't want it to run, I can kill it. Close the last one (or possibly even close the last window I'm not sure if it'll tolerate being run headless) and WSL shuts down, killing all of its processes. Microsoft, in their infinite wisdom, have decided that WSL (Windows Subsystem for Linux) will only run while you have a bash.exe process open. Sadly/absurdly, there is no way to do this. A recent build of Win10 (spring 2018 for public releases, build 17046 or greater) is required.

Background / daemon processes are now allowed to continue running even after bash.exe (or other WSL launcher process) is closed. Even if the command does not support setting the needed variable via a command line argument, it's possible to do it using bash itself: # direct, command-dependent For this, there needs to be a way to pass these variables. For instance, DISPLAY, if set in the windows normal method, is not passed to WSL. One thing I've found is that environment variables are not available. If you go into Windows' Task Manager, it will show a Sleep or Python2 command running for 20 seconds, then self-clearing. Wsl python -c 'import time time.sleep(20) ' & You can append an ampersand to the command (normal shell behavior), which results in a momentary bash terminal which immediately disappears but the command continues.Įxamples, within Start » Run: wsl sleep 20 &

A recent addition to WSL allows for starting wsl commands directly from the 'run' or Start menu.
