If you use Windows Subsystem for Linux (WSL), you may want to close a session when you have finished working, need to restart a Linux distribution, or want to free system resources. The right method depends on what you mean by “close”: you can exit the current Linux shell, stop one distribution, or shut down the WSL virtual machine and all its running distributions. This guide explains how to close a WSL session safely, which commands to use, and how to check that WSL has stopped.
What Does It Mean to Close a WSL Session?
A WSL session is the Linux command-line environment you open from Windows Terminal, PowerShell, Command Prompt, or another terminal app. Closing the terminal window or leaving the shell does not always mean that every Linux process has stopped. Background tasks and services may continue running, so it helps to choose the shutdown method that matches what you want to do.
There are three common levels of closing WSL:
- Exit the shell: Ends your current command-line session. Other processes or distributions may remain active.
- Terminate one distribution: Stops a selected Linux distribution, such as Ubuntu, and its running processes.
- Shut down WSL: Stops all running distributions and the WSL virtual machine.
For everyday use, exiting the shell is usually enough. If you need to stop a Linux environment completely, terminate its distribution. To restart WSL or stop everything WSL-related, use the full shutdown command.
How to Close a WSL Session by Exiting the Shell
The simplest way to close a WSL session is to enter exit at the Linux prompt. This ends the current shell and usually returns you to the Windows terminal that launched it.
exit
You can also press Ctrl+D while the shell is waiting for input. This sends an end-of-file signal, which normally closes the shell in the same way as the exit command.
For example, if you opened Ubuntu in Windows Terminal, typing exit should take you back to the Windows prompt or close the tab, depending on your terminal settings. If the tab remains open, close it using the terminal’s tab controls.
Exiting is a good choice when you have finished working and do not need to stop other WSL processes. It is also the quickest way to leave an interactive Linux shell. However, it may not stop programs that were started in the background, and it does not necessarily stop other distributions that are running.
How to Terminate a Specific WSL Distribution
To stop one Linux distribution completely, run wsl --terminate from PowerShell or Command Prompt. This ends the selected distribution and stops its running processes. It does not shut down other WSL distributions.
First, find the exact distribution name. In PowerShell or Command Prompt, run:
wsl --list --verbose
The output shows installed distributions, their state, and the WSL version they use. Use the name shown in the first column with the terminate command. For example:
wsl --terminate Ubuntu
If your distribution has a version number or a different name, use that exact name. For instance, a listed name such as Ubuntu-24.04 should be entered as Ubuntu-24.04, rather than shortened to Ubuntu.
You can also use the shorter command form:
wsl -t Ubuntu
Terminating a distribution is useful when an application inside Linux has stopped responding, when you need a clean restart, or when you want to stop one environment without interrupting another. Any unsaved work in running programs may be lost, so save files and stop important tasks before terminating the distribution.
How to Shut Down All WSL Distributions
If you want to close every running WSL distribution and stop the WSL virtual machine, use wsl --shutdown in PowerShell or Command Prompt:
wsl --shutdown
This command stops all running distributions, including those you did not open in the current terminal. It is often the best option when you need to restart the WSL environment, troubleshoot a problem affecting several distributions, or free resources used by WSL.
After shutdown, the next time you launch a distribution or run a WSL command that requires Linux, WSL starts again automatically. You do not need to manually restart a service or reopen a special WSL application.
Because this command affects every running distribution, check that you are not running work that should remain active. For example, a development server, database, file transfer, or long-running script can be stopped by shutting down WSL.
How to Close WSL from Windows Terminal
If you are using Windows Terminal, you can close the active tab or window with its tab controls or keyboard shortcut. This closes the terminal interface, but it is not always the same as shutting down WSL. A Linux process running in the background may keep the distribution active after the terminal closes.
To simply leave the interactive shell, enter exit first. To make sure a particular distribution stops, open a new PowerShell or Command Prompt window and run wsl --terminate with its name. To stop all distributions, run wsl --shutdown.
This distinction is useful when you notice that WSL is still using memory or CPU after you close a terminal tab. The terminal window is only the interface; WSL processes can continue independently of it.
How to Check Whether WSL Is Still Running
Use the following command in PowerShell or Command Prompt to see your installed distributions and their current states:
wsl --list --verbose
A distribution marked Running is active. A distribution marked Stopped is not currently running. You can also ask WSL to list only running distributions:
wsl --list --running
If you have just run wsl --terminate or wsl --shutdown, check the list again to confirm the result. Note that launching a new Linux command or application can start a distribution again, so a running state after shutdown may simply mean WSL was started by another command.
What to Do If WSL Will Not Close
If a distribution remains active after you exit the shell, another process may still be running. Use wsl --list --verbose to identify which distribution is active, then terminate that distribution by name. If you want to stop everything, use wsl --shutdown.
If a command appears to do nothing, make sure you are running it in Windows PowerShell or Command Prompt, not at the Linux prompt. The commands wsl --terminate and wsl --shutdown are Windows-side WSL commands. If you are currently inside Linux, type exit to return to Windows first.
You can also confirm that the distribution name is correct. Names may differ depending on the version installed. Copy the name from the output of wsl --list --verbose and use it exactly in the terminate command.
As a last resort, restarting Windows will stop WSL along with other running applications. Usually, however, wsl --shutdown is a faster and more targeted way to reset the WSL environment.
Important Safety Tips Before Closing WSL
- Save files and commit or back up important work before terminating a distribution.
- Stop services or scripts cleanly when possible, especially databases and development servers.
- Use
wsl --terminatewhen you only need to stop one distribution. - Use
wsl --shutdownwhen you intend to stop every running WSL distribution. - Do not use
wsl --unregisterto close a session. Unregistering removes a distribution and can delete its data.
The distinction between shutdown and unregister is especially important. Terminating or shutting down a distribution stops it temporarily; its files remain available the next time you launch it. Unregistering is a removal operation, not a session-closing command.
Conclusion
Closing a WSL session can mean simply leaving the Linux shell or stopping the entire Linux environment. Type exit or press Ctrl+D to close the current shell. Run wsl --terminate <DistributionName> to stop one distribution, or use wsl --shutdown to stop all running distributions and the WSL virtual machine. When in doubt, check the state with wsl --list --verbose, save your work, and choose the least disruptive command for your needs.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.