How to manually stop kestrel server
Asked Answered
I

9

31

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).

Idolah answered 11/8, 2016 at 21:32 Comment(3)
If you ran from the command line: Ctrl + CGallice
@BrunoGarcia I forgot to mention that doesn't work! Also, when I quit VS and/or restart it, the process still runs (page refreshes on Chrome)! Where do I find the relevant process and how do I kill it? I will Update the Q with extra info...Thanx!Idolah
Related issue. This is currently an issue with the cli terminating dotnet run doesn't terminate child #7426Flexion
N
37

On OSX Terminal:

sudo lsof -iTCP -sTCP:LISTEN -P | grep :5000

enter image description here

sudo kill -9 1872
Negation answered 25/4, 2017 at 17:2 Comment(0)
O
31

I ran this on powershell to kill all instances of the kestral server

Get-Process -Name *dotnet* | Stop-Process
Overmeasure answered 31/12, 2018 at 19:10 Comment(1)
Thank you - works a treat! (In Windows/VS Terminal too)Orban
L
9

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

Lengthen answered 27/12, 2017 at 11:12 Comment(1)
You may get : ERROR: The process with PID ... could not be terminated. Reason: Access is denied. Run cmd as Administrator.Saddlery
R
8

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

Rissa answered 25/2, 2017 at 16:11 Comment(1)
I don't see 'dotnet' in my list of tasks even though supposedly Kestrel is holding onto a site running in docker (even though I've fully stopped and removed the docker container)Philologian
D
5

The line below works for me.

killall -9 dotnet

Dogtrot answered 17/8, 2020 at 11:56 Comment(0)
B
4

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
Blah answered 18/6, 2018 at 23:22 Comment(0)
F
1

Save the following in a .cmd file and click on the file:

Taskkill.exe /F /IM dotnet.exe /T
Florentinaflorentine answered 28/1, 2021 at 23:25 Comment(0)
M
1

For macOS 12.6 (Monterey) with .NET Core 6 and 7, this command worked for me.

pgrep -f dotnet | xargs kill -9

Marceline answered 22/6, 2023 at 16:2 Comment(0)
R
0

Ctrl + Break also does the trick.

Rendition answered 21/6, 2021 at 4:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.