Advertisement

WSL Has Got Background Task Support

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.

Advertisеment

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.

Startup Tasks

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".Tmux New Session

To ensure that it is running in the background, you can use any process manager like ps or htop. Here is the htop output.Tmux Session In Htop

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:

tmux ls

You will find your previous session running:Tmux Reattach Session

You can re-activate it with the following command and continue where you left off.

tmux attach -t backgroundsession

Tmux Session Reconnected

Articles of interest:

Source: MSDN Blogs.

Support us

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!

Advertisеment

Author: Sergey Tkachenko

Sergey Tkachenko is a software developer who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.

Leave a Reply

Your email address will not be published.

css.php
Using Telegram? Subscribe to the blog channel!
Hello. Add your message here.