50

I'm trying to kill a dev server setup via yarn on Windows. While I Ctrl+C'd the command prompt, when I went back to localhost:8080 it had not stopped. How can I kill the process?

1
  • 3
    Had the process not stopped or had it restarted after being killed. I would expect Web processes to be run with a monitor to restart it after failures. – mmmmmm Mar 6 '19 at 11:09
101

You can track down the process running on port 8080 and kill it.

For macOS or Linux:

sudo lsof -iTCP:8080 -sTCP:LISTEN

You should get an output something like:

COMMAND   PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
yarn    12017 user   12u  IPv6 1876683      0t0  TCP *:8080 (LISTEN)

Now that you have the process ID(PID), you can kill the process. First try:

kill 12017(whatever the PID is)

If that does nothing, try:

kill -9 12017

For Windows:

netstat -ano | findstr :8080 (the port number)

This should give you the process to kill. You can then run:

taskkill /F /PID 12017(or whatever the process ID is)
6
  • 6
    For an 'all in one' linux command, check out fuser. fuser -k 8080/tcp 8080/udp should kill anything listening on 8080. – mbrig Mar 5 '19 at 18:32
  • 4
    NB: The Windows command will also list all local processes that are connected to the webserver, at the instant that the command was run. The left address:port pair is the source address, the right address:port is the destination. Adding -t tcp will only list TCP connections, not UDP connections – CSM Mar 5 '19 at 20:15
  • @Bakuriu : native Italian user here. Try to guess how that "ano" mnemonic sound hilarious (and unforgettable) to me... – Dr. Gianluigi Zane Zanettini Mar 6 '19 at 8:56
  • @mbrig That's cool, but it sends SIGKILL by default. To do kills where the program has a chance to clean up after itself and avoid possible corruption, you can change the signal by providing an option like you would with kill, for example -15 or -TERM or -2 or -INT. – JoL Mar 6 '19 at 20:41
  • Windows also has a built-in GUI for this: Resource Monitor (perfmon.exe /res). Under the Network tab, check "Listening Ports." – erobertc Mar 7 '19 at 8:16
7

If you install ProcessExplorer from SystemInternals, then you can see the process tree.

In ProcessExplorer, click the target-sight button, and then click on the cmd prompt that you launched the webrowser from. ProcessExplorer will then jump to that cmd prompt in its list. If the process view is not already threaded by parent-child relation, then press Ctrl-T a few times until it is. You then should be able to see the webserver. Select it, and then right-click on it. Select "Kill Process Tree" to forcibly kill the webserver.

SystemInternals also has pskill. You can use pskill -t "MyWebServer" to kill all processes, and their children, than are called MyWebServer.

-1

In a single command:

kill -INT $(lsof -t -i :8080)

Or more generally:

kill -INT $(lsof -t -i :PORT_NUMBER)

Additional Notes:

$() is called "Command Substitution"

-4

Unless the process you're trying to kill is one that gets started upon booting the server, rebooting the computer in question would probably work. It's probably a last resort option due to losing everything else the computer's been doing that hasn't been saved, and the time it takes for the reboot to occur, but there's a reason why a lot of IT professionals start their troubleshooting process for user machines with "Have you tried turning the computer off and back on again?"

3
  • 1
    Not sure why I'm being downvoted. "Reboot the computer" is a valid solution for the problem asked by the OP. – nick012000 Mar 6 '19 at 2:40
  • 5
    Not my downvote, but this solution is a vast overkill. "Turn it off and on again" is mostly useful when you are debugging somebody else's problem and don't care about their inconvenience. – Stig Hemmer Mar 6 '19 at 9:46
  • (not my down) It is clearly not a user-level problem. Maybe a super-superuser level problem. – peterh Mar 6 '19 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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