Linux: find thin server running on port 80 and kill it

Andrew asked:

On my Linux server I ran:

sudo thin start -p 80 -d

Now I’d like to restart the sever. The trouble is, I can’t seem to get the old process to kill it. I tried:

netstat -anp

But what I see on port 80 is this:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -         

So, it didn’t give me a PID to kill…

I tried pgrep -l thin but that gave me nothing. Meanwhile pgrep -l ruby gives me like 6 processes running. I don’t really understand why multiple ruby threads would be running, or which one I need to kill…

How do I kill / restart the thin daemon?

My answer:


thin is a Ruby gem, so it only makes sense that the Ruby interpreter would be running it.

A typical invocation of thin would be:

bundle exec rails server thin -p $PORT -e $RACK_ENV

In the process list, from the ps command, this appears something like:

 6870 pts/3    Rl+    0:01 /usr/bin/ruby script/rails server thin -p 80 -e production

When using pgrep, by default it only matches against the command name (i.e. ruby). This won’t match when the pattern you’re searching for appears in the arguments. For this, you need to use the -f option as well:

pgrep -l -f thin

The return then appears like this:

6870 /usr/bin/ruby script/rails server thin -p 80 -e production

And voila, there is the process you’re looking for.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.