Starting with Windows 10 build 17046, Windows Subsytem for Linux (WSL) has got support for long-running background tasks, similar to how the Windows subsystem has Services. This is a really impressive change for users of WSL who work with servers like Apache or apps like screen or tmux. Now they can run in the background like regular Linux daemons. The ability to run daemons was missing and was highly requested by users.
Elevated and Non-elevated Instances
Besides daemon support, WSL can now have both elevated and non-elevated process instances simultaneously without affecting the permissions in other sessions.
WSL in build 17046 and above now supports startup tasks. While it lacks support of classic Linux init systems like SysV or OpenRC as well as the modern SystemD init system, it is possible now to build a custom startup script or use Task Scheduler.
Background Tasks in Action
To test the background tasks feature in action, upgrade your Insider Preview instance to Windows 10 build 17046 and install some app which can run in the background. For example, it can be tmux, the virtual multiplexer app.
You can create a new tmux background session with the following command:
tmux new -s backgroundsession
The session will be simply named "backgroundsession".
To ensure that it is running in the background, you can use any process manager like ps or htop. Here is the htop output.
Now, you can close the WSL window and the task will remain running!
To check this out, open a new WSL window and check out available tmux sessions with the command:
You will find your previous session running:
You can re-activate it with the following command and continue where you left off.
tmux attach -t backgroundsession
Articles of interest:
- Enable WSL in Windows 10
- Set Default User for WSL in Windows 10
- Install Linux Distros from Microsoft Store in Windows 10
Source: MSDN Blogs.
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!