title: How to I close down a python server built using flask
body: <p>When I run this simple code:</p>
  
  <p><code>from flask import Flask,render_template</code></p>
  
  <p><code>app = Flask(__name__)</code></p>
  
  <p><code>@app.route('/')</code>
  <code>def index():
      return 'this is the homepage'</code></p>
  
  <p><code>if __name__ ==  "__main__":
      app.run(debug=True, host="0.0.0.0",port=8080)</code></p>
  
  <p>It works fine but when I close it using ctrl+z in the terminal and try to run it again I get <code>OSError: [Errno 98] Address already in use</code></p>
  
  <p>So I tried changing the port address and re-running it which works for some of the port numbers I enter. But I want to know a graceful way to clear the address being used by previous program so that it is free for the current one. 
  Also is what is the apt way to shutdown a server and free the port address.</p>
  
  <p>Kindly tell a simple way to do so OR explain the method used fully because I read solutions to similar problems but didn't understand any of it.</p>
  
  <p>When I run
  <code>netstat -tulpn</code>
  The output is : </p>
  
  <p><code>(Not all processes could be identified, non-owned process info
   will not be shown, you would have to be root to see it all.)
  Active Internet connections (only servers)
  Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
  tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      -<br>
  tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -<br>
  tcp        0      0 0.0.0.0:3689            0.0.0.0:*               LISTEN      4361/rhythmbox<br>
  tcp6       0      0 ::1:631                 :::*                    LISTEN      -<br>
  tcp6       0      0 :::3689                 :::*                    LISTEN      4361/rhythmbox<br>
  udp        0      0 0.0.0.0:5353            0.0.0.0:*                           3891/chrome<br>
  udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -<br>
  udp        0      0 0.0.0.0:39223           0.0.0.0:*                           -<br>
  udp        0      0 127.0.1.1:53            0.0.0.0:*                           -<br>
  udp        0      0 0.0.0.0:68              0.0.0.0:*                           -<br>
  udp        0      0 0.0.0.0:631             0.0.0.0:*                           -<br>
  udp        0      0 0.0.0.0:58140           0.0.0.0:*                           -<br>
  udp6       0      0 :::5353                 :::*                                3891/chrome<br>
  udp6       0      0 :::5353                 :::*                                -<br>
  udp6       0      0 :::41938                :::*                                -</code></p>
  
  <p>I'm not sure how to interpret it.    </p>
  
  <p>the output of <code>ps aux | grep 8080</code> 
  is :</p>
  
  <p><code>shreyash 22402  0.0  0.0  14224   928 pts/2    S+   01:20   0:00 grep --color=auto 8080</code></p>
  
  <p>I don't know how to interpret it.
  Which one is the the process name and what is it's id?</p>