Indicates whether a context is capable of using features that require secure contexts. Window.length Read only Returns the number of frames in the window. See also window.frames. Window.location Gets/sets the location, or current URL, of the window object. Window.locationbar Read only. Sep 14, 2017 Switch, Window-Based Context Switching. Switch is a window-based (as opposed to application-based) context switcher. By default it is bound to using ⌥⇥ and ⌥⇧⇥ to cycle through the visible windows on the current space. When the interface is active, ⌥W can be used to close windows and ⌥, used to show a preferences window.
-->The primary difference and reasons for updating the Windows Subsystem for Linux from WSL 1 to WSL 2 are to:
WSL 2 uses the latest and greatest in virtualization technology to run a Linux kernel inside of a lightweight utility virtual machine (VM). However, WSL 2 is not a traditional VM experience.
Feature | WSL 1 | WSL 2 |
---|---|---|
Integration between Windows and Linux | ✅ | ✅ |
Fast boot times | ✅ | ✅ |
Small resource foot print | ✅ | ✅ |
Runs with current versions of VMware and VirtualBox | ✅ | ✅ |
Managed VM | ❌ | ✅ |
Full Linux Kernel | ❌ | ✅ |
Full system call compatibility | ❌ | ✅ |
Performance across OS file systems | ✅ | ❌ |
As you can tell from the comparison table above, the WSL 2 architecture outperforms WSL 1 in several ways, with the exception of performance across OS file systems.
We recommend against working across operating systems with your files, unless you have a specific reason for doing so. For the fastest performance speed, store your files in the WSL file system if you are working in a Linux command line (Ubuntu, OpenSUSE, etc). If you're working in a Windows command line (PowerShell, Command Prompt), store your files in the Windows file system.
For example, when storing your WSL project files:
wsl$Ubuntu-18.04home<user name>Project
C:Users<user name>Project
All currently running distributions (wsl -l
) are accessible via network connection. To get there run a command [WIN+R] (keyboard shortcut) or type in File Explorer address bar wsl$
to find respective distribution names and access their root file systems.
You can also use windows commands inside WSL's Linux Terminal. Try opening a Linux distribution (ie Ubuntu), be sure that you are in the Linux home directory by entering this command: cd ~
. Then open your Linux file system in File Explorer by entering (don't forget the period at the end): powershell.exe /c start .
Important
If you experience an error -bash: powershell.exe: command not found please refer to the WSL troubleshooting page to resolve it.
WSL 2 is only available in Windows 10, Version 1903, Build 18362 or higher. Check your Windows version by selecting the Windows logo key + R, type winver, select OK. (Or enter the ver
command in Windows Command Prompt). You may need to update to the latest Windows version. For builds lower than 18362, WSL is not supported at all.
Note
WSL 2 will work with VMware 15.5.5+ and VirtualBox 6+. Learn more in our WSL 2 FAQs.
WSL 2 is a major overhaul of the underlying architecture and uses virtualization technology and a Linux kernel to enable new features. The primary goals of this update are to increase file system performance and add full system call compatibility.
A traditional VM experience can be slow to boot up, is isolated, consumes a lot of resources, and requires your time to manage it. WSL 2 does not have these attributes.
WSL 2 provides the benefits of WSL 1, including seamless integration between Windows and Linux, fast boot times, a small resource footprint, and requires no VM configuration or management. While WSL 2 does use a VM, it is managed and run behind the scenes, leaving you with the same user experience as WSL 1.
The Linux kernel in WSL 2 is built by Microsoft from the latest stable branch, based on the source available at kernel.org. This kernel has been specially tuned for WSL 2, optimizing for size and performance to provide an amazing Linux experience on Windows. The kernel will be serviced by Windows updates, which means you will get the latest security fixes and kernel improvements without needing to manage it yourself.
The WSL 2 Linux kernel is open source. If you'd like to learn more, check out the blog post Shipping a Linux Kernel with Windows written by the team that built it.
File intensive operations like git clone, npm install, apt update, apt upgrade, and more are all noticeably faster with WSL 2.
The actual speed increase will depend on which app you're running and how it is interacting with the file system. Initial versions of WSL 2 run up to 20x faster compared to WSL 1 when unpacking a zipped tarball, and around 2-5x faster when using git clone, npm install and cmake on various projects.
Linux binaries use system calls to perform functions such as accessing files, requesting memory, creating processes, and more. Whereas WSL 1 used a translation layer that was built by the WSL team, WSL 2 includes its own Linux kernel with full system call compatibility. Benefits include:
A whole new set of apps that you can run inside of WSL, such as Docker and more.
Any updates to the Linux kernel are immediately ready for use. (You don't have to wait for the WSL team to implement updates and add the changes).
WSL 2 uses a lightweight utility VM on a real Linux kernel with a small memory footprint. The utility will allocate Virtual Address backed memory on startup. It is configured to start with a smaller proportion of your total memory that what was required for WSL 1.
We recommend that you use WSL 2 as it offers faster performance and 100% system call compatibility. However, there are a few specific scenarios where you might prefer using WSL 1. Consider using WSL 1 if:
Note
Consider trying the VS Code Remote WSL Extension to enable you to store your project files on the Linux file system, using Linux command line tools, but also using VS Code on Windows to author, edit, debug, or run your project in an internet browser without any of the performance slow-downs associated with working across the Linux and Windows file systems. Learn more.
If you are building a networking app (for example an app running on a NodeJS or SQL server) in your Linux distribution, you can access it from a Windows app (like your Edge or Chrome internet browser) using localhost
(just like you normally would).
However, if you are running an older version of Windows (Build 18945 or less), you will need to get the IP address of the Linux host VM (or update to the latest Windows version).
To find the IP address of the virtual machine powering your Linux distribution:
ip addr
inet
value of the eth0
interface.ip addr grep eth0
The picture below shows an example of this by connecting to a Node.js server using the Edge browser.
If you want to access a networking app running on Windows (for example an app running on a NodeJS or SQL server) from your Linux distribution (ie Ubuntu), then you need to use the IP address of your host machine. While this is not a common scenario, you can follow these steps to make it work.- Obtain the IP address of your host machine by running this command from your Linux distribution: cat /etc/resolv.conf
- Copy the IP address following the term: nameserver
.- Connect to any Windows server using the copied IP address.
The picture below shows an example of this by connecting to a Node.js server running in Windows via curl.
When using remote IP addresses to connect to your applications, they will be treated as connections from the Local Area Network (LAN). This means that you will need to make sure your application can accept LAN connections.
For example, you may need to bind your application to 0.0.0.0
instead of 127.0.0.1
. In the example of a Python app using Flask, this can be done with the command: app.run(host='0.0.0.0')
. Please keep security in mind when making these changes as this will allow connections from your LAN.
When using a WSL 1 distribution, if your computer was set up to be accessed by your LAN, then applications run in WSL could be accessed on your LAN as well.
This isn't the default case in WSL 2. WSL 2 has a virtualized ethernet adapter with its own unique IP address. Currently, to enable this workflow you will need to go through the same steps as you would for a regular virtual machine. (We are looking into ways to improve this experience.)
Here's an example PowerShell command to add a port proxy that listens on port 4000 on the host and connects it to port 4000 to the WSL 2 VM with IP address 192.168.101.100.
WSL 2 distributions currently cannot reach IPv6-only addresses. We are working on adding this feature.
WSL 2 uses a Virtual Hard Disk (VHD) to store your Linux files. In WSL 2, a VHD is represented on your Windows hard drive as a .vhdx file.
The WSL 2 VHD uses the ext4 file system. This VHD automatically resizes to meet your storage needs and has an initial maximum size of 256GB. If the storage space required by your Linux files exceeds this size you may need to expand it. If your distribution grows in size to be greater than 256GB, you will see errors stating that you've run out of disk space. You can fix this error by expanding the VHD size.
To expand your maximum VHD size beyond 256GB:
Terminate all WSL instances using the command: wsl --shutdown
Find your distribution installation package name ('PackageFamilyName')
Get-AppxPackage -Name '*<distro>*' Select PackageFamilyName
Locate the VHD file fullpath
used by your WSL 2 installation, this will be your pathToVHD
:
%LOCALAPPDATA%Packages<PackageFamilyName>LocalState<disk>.vhdx
Resize your WSL 2 VHD by completing the following commands:
Open Windows Command Prompt with admin privileges and enter:
Examine the output of the detail command. The output will include a value for Virtual size. This is the current maximum. Convert this value to megabytes. The new value after resizing must be greater than this value. For example, if the detail output shows Virtual size: 256 GB, then you must specify a value greater than 256000. Once you have your new size in megabytes, enter the following command in diskpart:
Exit diskpart
Launch your WSL distribution (Ubuntu, for example).
Make WSL aware that it can expand its file system's size by running these commands from your Linux distribution command line.
Note
You may see this message in response to the first mount command: /dev: none already mounted on /dev. This message can safely be ignored.
Copy the name of this entry, which will look like: /dev/sdX
(with the X representing any other character). In the following example the value of X is b:
Note
You may need to install resize2fs. If so, you can use this command to install it: sudo apt install resize2fs
.
The output will look similar to the following:
Note
In general do not modify, move, or access the WSL related files located inside of your AppData folder using Windows tools or editors. Doing so could cause your Linux distribution to become corrupted.
In the Operating System, there are cases when you have to bring back the process that is in the running state to some other state like ready state or wait/block state. If the running process wants to perform some I/O operation, then you have to remove the process from the running state and then put the process in the I/O queue. Sometimes, the process might be using a round-robin scheduling algorithm where after every fixed time quantum, the process has to come back to the ready state from the running state. So, these process switchings are done with the help of Context Switching. In this blog, we will learn about the concept of Context Switching in the Operating System and we will also learn about the advantages and disadvantages of Context Switching. So, let's get started.
A context switching is a process that involves switching of the CPU from one process or task to another. In this phenomenon, the execution of the process that is present in the running state is suspended by the kernel and another process that is present in the ready state is executed by the CPU.
It is one of the essential features of the multitasking operating system. The processes are switched so fastly that it gives an illusion to the user that all the processes are being executed at the same time.
But the context switching process involved a number of steps that need to be followed. You can't directly switch a process from the running state to the ready state. You have to save the context of that process. If you are not saving the context of any process P then after some time, when the process P comes in the CPU for execution again, then the process will start executing from starting. But in reality, it should continue from that point where it left the CPU in its previous execution. So, the context of the process should be saved before putting any other process in the running state.
A context is the contents of a CPU's registers and program counter at any point in time. Context switching can happen due to the following reasons:
The process of context switching involves a number of steps. The following diagram depicts the process of context switching between the two processes P1 and P2.
In the above figure, you can see that initially, the process P1 is in the running state and the process P2 is in the ready state. Now, when some interruption occurs then you have to switch the process P1 from running to the ready state after saving the context and the process P2 from ready to running state. The following steps will be performed:
For context switching to happen, two processes are at least required in general, and in the case of the round-robin algorithm, you can perform context switching with the help of one process only.
The time involved in the context switching of one process by other is called the Context Switching Time.
Context switching is used to achieve multitasking i.e. multiprogramming with time-sharing(learn more about multitasking from here). Multitasking gives an illusion to the users that more than one process are being executed at the same time. But in reality, only one task is being executed at a particular instant of time by a processor. Here, the context switching is so fast that the user feels that the CPU is executing more than one task at the same time.
The disadvantage of context switching is that it requires some time for context switching i.e. the context switching time. Time is required to save the context of one process that is in the running state and then getting the context of another process that is about to come in the running state. During that time, there is no useful work done by the CPU from the user perspective. So, context switching is pure overhead in this condition.
That's it for this blog. Hope you enjoyed this blog.
Do share this blog with your friends to spread the knowledge. Visit our YouTube channel for more content.
Keep Learning :)
Team AfterAcademy!