Killing (Almost) Any Process on Linux

Killing (Almost) Any Process on Linux

Have you ever accidentally turned off your Rails server with ctrl+Z?
I know I did and here are some simple guidelines to kill that Rails server process so you can restart it again.

Find PID of process you want to turn off

Open terminal and type lsof -i :number_of_port to find PID of the process you want to kill. For example, if your Rails server is running on port 3000, the command will look like this:

lsof -i :3000

The output of this command should be something like this:

COMMAND  PID   USER     FD   TYPE  DEVICE  SIZE/OFF NODE NAME
ruby     1438  ubuntu   14u  IPv4  691363  0t0      TCP  localhost:3000 (LISTEN)

Kill the process

In terminal type kill -9 PID_OF_PROCESS to kill the process! You can find PID of process under PID column of lsof -i command.
In our case the command would look like this:

kill -9 1438

And that is it! You have successfully killed this process and you can restart your Rails server.