30

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

3
  • If you ran from the command line: Ctrl + C Aug 11, 2016 at 21:34
  • @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! Aug 11, 2016 at 21:56
  • Related issue. This is currently an issue with the cli terminating dotnet run doesn't terminate child #7426
    – stormwild
    Oct 1, 2017 at 4:49

8 Answers 8

36

On OSX Terminal:

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

enter image description here

sudo kill -9 1872
0
29

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

Get-Process -Name *dotnet* | Stop-Process
1
  • Thank you - works a treat! (In Windows/VS Terminal too)
    – dalcam
    Dec 10, 2020 at 1:58
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

2
  • You may get : ERROR: The process with PID ... could not be terminated. Reason: Access is denied. Run cmd as Administrator. Sep 9, 2019 at 18:34
  • @HorasanLee run your cmd or terminal in administrator mood Sep 10, 2019 at 2:29
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

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) Feb 22, 2018 at 5:22
5

The line below works for me.

killall -9 dotnet

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
1

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

Taskkill.exe /F /IM dotnet.exe /T
0

Ctrl + Break also does the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.