Skip to main content

Windows Subsystem for Linux Internals

Background

Windows Subsystem for Linux was developed by Microsoft to enable command line programs compiled for the Linux operating system to be executed on Windows.

To explain the architecture I would like to show the evolution of OS design and how that has enabled this subsystem to be built.

Dark Ages (or Back in the Day)

Microsoft's MS-DOS was quite primitive in its design (compared to today's OS's). It is a single user OS that can execute one process at a time. DOS had an application programming interface to allow user programs to access some hardware in a device independent way, but only for character-based applications.

This allowed applications to display graphical elements emulated with text characters as these screenshots of Microsoft word for DOS show:


This is Microsoft Word version 1.


To use these programs you had to remember key combinations to bring up the menus and used the cursor keys to navigate around the screen.

If the application required fancy graphics, sounds or networking (or just wanted to allow the use of a mouse), then the application had to talk directly to that hardware using device-specific drivers.



If you changed your sound/network/video card, applications might stop working as they might not have drivers for it.

Windows

On 20th November 1985 Microsoft launched Windows version 1.0.

The first version of Windows ran on top of MS-DOS and presented a Graphical User Interface.


Windows 1 introduced the hardware abstraction layer into the PC application architecture. Windows 1 included drivers for video cards, a mouse, keyboards, printers and serial communications, and applications were supposed to only invoke The Windows APIs and not talk to the drivers directly.

The windows OS has evolved a great deal over the years and the original windows 1 architecture was still in use as the foundation of Windows ME release in 2000.

Starting in 1993 Microsoft created a purely 32 bit OS with no legacy code from Windows 1 architecture. The kernel created for Windows NT is still used as the base for current versions of Windows (although it has evolved since 1993).

This is the basic structure of windows today. User applications talk to a layer in the kernel that abstracts out all details of the hardware and presents a unified API to user applications.


## Linux

In 1991, Linus Torvalds, a student at Helsinki university wanted an OS where he could play with its source code and learn about its internals. He started using an OS called Minix written by professor Andrew Tanenbaum and documented in a book which was aimed at students learning operating systems design. While the source code for the Minix system was available, modification and redistribution were restricted.

This led Linus Torvalds to start writing his own OS which he called Linux.

The first message about Linux was actually posted to the comp.os.minix newsgroup on 25 Aug 1991 - First msg about Linux

Linux has a similar architecture to current Windows versions. no user application accesses hardware devices directly not even by talking to device drivers. User applications talk to a layer in the kernel that abstracts out all details of the hardware and presents a unified API to user applications.


Windows Subsystem for Linux

So, finally on to the subject of this post.

Microsoft hasn't always been a fan of Linux. Some people have even accused Microsoft of underhand tactics in the past designed to stop Linux being installed on PC's that also had Windows installed.

But eventually, they have realised that developers seem to like the open source OS and have started supporting it.

Windows Subsystem for Linux-August 2, 2016 (Windows 10 Build 1607

the Windows subsystem for Linux was written to allow text mode Linux programs to be executed on windows.

"WSL executes unmodified Linux ELF64 binaries by virtualizing a Linux kernel interface on top of the Windows NT kernel"

Basically, it performs real-time translation of Linux syscalls into Windows OS syscalls.




So what it boils down to is that Microsoft wrote a Linux kernel 'emulator', which allows programs that call into the Linux kernel user-space API to execute on windows and not know it. But being only the Linux kernel, there are no graphics calls. Sorry but Xeyes won't run. Unix has a unique take on windowing systems. but that is a large subject and probably best left for another post. This one is long enough for now.

References



Comments

Popular posts from this blog

What does "Full Stack" mean?

I've been a software engineer for a little while and I see the term "Full Stack developer" more and more, but what does it mean? Okay, let's walk through what a complete system will comprise of and see if we can work it out. UI First (from the users perspective) is the UI. It's how they interact and really all they care about (as long as the application does what is expected of it. Here is a list of some UI technologies that I know of AWT Swing Qt Android XML MFC and VB OpenGl Vulkan Communication Protocol Next up is the communications protocol (as most applications these days are a thin UI talking to a backend server (we've gone back to the mainframe era!) RPC FTP SNMP SMTP DDS ActiveMq/RabbitMq Network Layer The communications protocol has to be transported between the client and the server somehow, so here we have the network layer IPX/SPX Token Ring Bluetooth USB Server So now we have data being transferred between t

Triathlon Training in the new year

So, my 2019 training has got off to a good start. I'm running regularly and my knees seem to be holding up. I've got a training plan to get me to a middle distance triathlon in September and I am managing the run distances I have set myself. I need to find some longer cycling routes to work and ones with a few hills too, but that shouldn't be a problem. my weekly cycling distance is okay, I just need to move to get my ebike to be doing less of the work. last week I did use my normal commuter bicycle and managed the whole four days as well as my runs, so that was a really good sign. Swimming won't be an issue, I have always found that to be the easy part of a triathlon (not that I'm fast, but I can keep going, and I did manage to swim the distance within the cut off time when I tried the ironman 70.3 last time) The main worry about going longer is my knees. I've got a 10K booked in late January which will test my knees out and I'm hoping that they hold