Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails server says port already used, how to kill that process?

I'm on a mac, doing:

rails server 

I get:

2010-12-17 12:35:15] INFO  WEBrick 1.3.1 [2010-12-17 12:35:15] INFO  ruby 1.8.7 (2010-08-16) [i686-darwin10.4.0] [2010-12-17 12:35:15] WARN  TCPServer Error: Address already in use - bind(2) Exiting 

I know I can start one on a new port, but I want to kill this process.

like image 277
Blankman Avatar asked Dec 17 '10 17:12

Blankman


People also ask

How do you kill a Rails process?

One way to shut down a rogue server is with the kill command. For the PID output above, you could kill the corresponding stuck server using kill 42612 . And if that didn't work, you could try kill -9 42612 .

How do you kill a Rails server that is already running?

The best solution is to delete the file Server. pids outputs is the process id. You should kill -9 processid , replacing the process id with the 4 numbers that vim (or other editor) outputed.


2 Answers

Assuming you're looking to kill whatever is on port 3000 (which is what webrick normally uses), type this in your terminal to find out the PID of the process:

$ lsof -wni tcp:3000 

Then, use the number in the PID column to kill the process:

$ kill -9 PID 
like image 195
idlefingers Avatar answered Sep 27 '22 18:09

idlefingers


kill -9 $(lsof -i tcp:3000 -t)

like image 40
Bijan Avatar answered Sep 27 '22 19:09

Bijan