Can't restart WSL2, LxssManager hangs in stopping state, how to restart? [closed]
Asked Answered
T

5

45

I Can't restart wsl2, the command wsl --shutdown and any other wsl command hangs forever. Also I found the service LxssManager in stopping status also hangs forever.

How can I restart wsl ?

Toritorie answered 3/1, 2022 at 14:52 Comment(0)
T
140

It looks like the hang LxssManager service is preventing wsl to restart, I found a way to stop LxssManager and then I was able to restart wsl normally.

First get the PID of svchost.exe running LxssManager, open the cmd as administrator and run:

tasklist /svc /fi "imagename eq svchost.exe" | findstr LxssManager

Grab the returned PID, then run task manager as administrator, in the details tab, search for the svchost.exe containing the PID, right click it and select 'end process tree'.

Now you should be able to restart wsl normally with 'wsl shutdown and wsl.

Toritorie answered 3/1, 2022 at 14:52 Comment(6)
Small improvement to the command: tasklist /svc /fi "imagename eq svchost.exe" | findstr LxssManagerTriglyceride
Thanks, this helped! In Windows 11, you can also find the PID of a service in Task Manager's Services tab. Typing L etc. will take you to services starting with that letter.Catafalque
omg, thank you! WSL sometimes gets stuck after sleep like this and I hate having to reboot for services that won't respond. You saved the day.Scheller
I've been getting this issue a lot lately on Windows 11 when waking the machine after sleep. Thank you for this fix!Tessellated
Although I landed here looking for a solution to the problem of "Docker starting forever", killing LxssManager as described solved my problem in a nice non-destructive way. Thank you.Erection
Alternatively you coud use tasklist /svc /fi "services eq LxssManager"Ribbonfish
S
3

I was in the same situation and restarting LxssManager service solved my problem.

Start a command prompt with administrative rights (I am logged with a normal user) and copy and paste in order to run the following commands:

sc.exe queryex LxssManager
sc.exe stop LxssManager
sc.exe start LxssManager
sc.exe queryex LxssManager

P.S. If after the second queryex command LxssManager PID is not different then stop did not succeed and you should try to run the commands after switching user to an administrative one.

P.P.S. If you still cannot stop the service, you should use Task Manager to "End process tree" in Details tab (using the PID displayed by queryex command). Make sure you are signed in (is more powerfull than 'run as') as an administrative user.

Sideling answered 26/10, 2022 at 18:21 Comment(2)
What if LxssManager is trying to stop but never ending and so stop is not possible? (I am getting crazy)Pyjamas
@StefanoScarpanti I was in that situation (after stop command from command prompt as a normal user, Task manager was displaying stopping). I could not "End process tree" from Task Manager "Run as" administrator. But I succeed to stop the service when I switched user to an administrative one. Of course a reboot will do the same but it takes longer.Sideling
G
3

In PowerShell 7 you can use

Get-CimInstance -ClassName Win32_Service -Filter "Name='LxssManager'"

to find PID of the process. In my case the State of the returned object is Stop Pending. Use the returned PID to kill LxssManager:

Stop-Process -Id $(Get-CimInstance -ClassName Win32_Service -Filter "Name='LxssManager'").ProcessId -Force

This made wsl.exe responsive again on my machine.

Getaway answered 20/4, 2023 at 15:15 Comment(1)
This looks really helpful but gives me Access is Denied in an Administrative Powershell.Comeback
N
2

If you can't kill / restart the process from neither cmd, powershell and task manager (on administrative account), what worked for me was using this tool https://github.com/winsiderss/systeminformer/releases/tag/v2.39.

In this thread it is explained why this type of processes can be almost unkillable https://github.com/microsoft/WSL/issues/1086.

Nakia answered 29/1, 2023 at 1:53 Comment(0)
J
0

For wsl2 try:

on CMD with admin access:

taskkill /F /FI "IMAGENAME eq wsl.exe"
taskkill /F /FI "IMAGENAME eq wslhost.exe"
taskkill /F /FI "IMAGENAME eq wslservice.exe"
Jerrome answered 10/2, 2023 at 8:22 Comment(2)
I get ERROR: The search filter cannot be recognized.Emmetropia
@Emmetropia I had the same error and I fixed the three eq operation. On my side just killing the wslservice.exe kills all the others. This is the only way I found now as the LxssManager related answers are no more working for my blocked WSL2.Raeleneraf

© 2022 - 2024 — McMap. All rights reserved.