I am doing this basic tutorial: http://www.asp.net/get-started
It suggests doing some changes, then running dotnet run
again. However, Ctrl+C isn't working and the Package Manager Console seems frozen. When I exit VS and/or restart it, I do my changes and dotnet run
again.
When I am doing this, I am getting an error (not the same every time), because the server is already running. The question is simple as 1-2-3:
How do I manually stop the kestrel server? (I am running Windows 10).
I ran this on powershell to kill all instances of the kestral server
Get-Process -Name *dotnet* | Stop-Process
For windows users:
Run netstat -ano -p TCP | find /I "listening" | find /I "port number"
then run taskkill /F /PID process ID
on Command Prompt.
Here is an example
C:\Users\Kiran>netstat -ano -p TCP | find /I "listening" | find /I "2492"
TCP 127.0.0.1:2492 0.0.0.0:0 LISTENING 820
C:\Users\Kiran>taskkill /F /PID 820
SUCCESS: The process with PID 820 has been terminated.
Here netstat -ano -p TCP | find /I "listening" | find /I "2492"
finds the process running TCP protocol listening on port 2492. And taskkill /F /PID 820
command to forcefully terminate the process with id 820
If anything else fails you can simply close it from the task manager. The name of the process would be dotnet. If you have Visual Studio open (in my case at least), there may be at least one other dotnet process running. Could not distinguish between them using only the task manager...
PS: When launching Kestrel with dotnet run from the PMC, in the console you get this:
Now listening on: http://localhost:5000 Application started. Press Ctrl+C to shut down.
But it didn't work to stop it with Ctrl+C
Stumbled upon it today. The answer above looks cool but netstat is slow. A simpler way to kill kestrel would be to use the PowerShell commandlet Get-NetTCPConnection.
To kill kestrel listening on Port 5000, the command would be
$pId = (Get-NetTCPConnection -LocalPort 5000).OwningProcess[0]
kill -Id $pId
Save the following in a .cmd file and click on the file:
Taskkill.exe /F /IM dotnet.exe /T
For macOS 12.6 (Monterey) with .NET Core 6 and 7, this command worked for me.
pgrep -f dotnet | xargs kill -9
© 2022 - 2024 — McMap. All rights reserved.
dotnet run
doesn't terminate child #7426 – Flexion