23 February 2026

Knowing port number, how to kill a process which is using that port?

  • Find what's sitting on the port:  

    $ sudo lsof -i :8000 (Replace 8000 with your port)

  • Kill that specific listener:  

    $ sudo kill -9 <PID_FROM_LSOF>


If I am running -

$ gunicorn --bind 0.0.0.0:8000 app:app
[2026-02-23 10:38:25 -0500] [250191] [INFO] Starting gunicorn 25.1.0
[2026-02-23 10:38:25 -0500] [250191] [INFO] Listening at: http://0.0.0.0:8000 (250191)
[2026-02-23 10:38:25 -0500] [250191] [INFO] Using worker: sync
[2026-02-23 10:38:25 -0500] [250191] [INFO] Control socket listening at /home/shermanchen/dev/convShop2/gunicorn.ctl
[2026-02-23 10:38:25 -0500] [250193] [INFO] Booting worker with pid: 250193

 

When I run lsof, I get -

$ sudo lsof -i :8000                           
COMMAND     PID        USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME                            
gunicorn 250191 shermanchen    3u  IPv4 1077472      0t0  TCP *:8000 (LISTEN)                 
gunicorn 250193 shermanchen    3u  IPv4 1077472      0t0  TCP *:8000 (LISTEN) 

 

If I kill the 'booting worker' pid 250193, the gunicorn will not be killed.  I have to kill the 'listening' pid 250191, to kill the gunicorn process.

$ sudo kill -9 250191

  

If I use ps, I got

$ ps aux | grep gunicorn                       
sherman+  250690  0.0  0.0   9824  2172 pts/1    S+   10:45   0:00 grep --color=auto gunicorn 
 

Killing pid 250690 will not kill the gunicorn process.

No comments:

Post a Comment