How to determine which process is using a port in Linux
<p>I'm currently running RethinkDB on its default port, because if I point my browser to <code>localhost:8080</code> I see the RethinkDB web interface:</p>

<p><a href="http://i.stack.imgur.com/vtGXl.png" rel="nofollow"><img src="http://i.stack.imgur.com/vtGXl.png" alt="enter image description here"></a></p>

<p>I'd like to close RethinkDB and re-open it on another port using the <code>--port-offset</code> argument. However, so far I haven't been able to close it from within Python using the <code>conn.close()</code> method.</p>

<p>Instead, I'd like to try a brute-force approach by simply killing the process using that port. I tried to determine which process that is by using <code>netstat</code>, but that doesn't bring up any results:</p>

<pre><code>kurt@kurt-ThinkPad:~$ netstat -a | grep 8080
kurt@kurt-ThinkPad:~$ 
</code></pre>

<p>How can I kill the RethinkDB process to make the port available again?</p>

<p>Following <a href="http://stackoverflow.com/users/3929826/klaus-d">Klaus D.</a>'s comment, I determined the process using <code>netstat -nlp</code>:</p>

<pre><code>kurt@kurt-ThinkPad:~$ netstat -nlp | grep 8080
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.1.1:8080          0.0.0.0:*               LISTEN      2229/rethinkdb  
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      2229/rethinkdb  
tcp6       0      0 ::1:8080                :::*                    LISTEN      2229/rethinkdb 
</code></pre>

<p>The arguments stand for </p>

<ul>
<li><code>numeric</code> (show numerical addresses instead of trying to determine symbolic host, port or usernames)</li>
<li><code>listening</code> (show only listening sockets (these are omitted by default))</li>
<li><code>program</code> (show the PID and name of the program to which each socket belongs)</li>
</ul>

<p>respectively.</p>

python linux rethinkdb