How can I release a port that is still in use but not bound to a process?
5,255
This did the trick
sudo kill -9 `ps -C python | grep python | grep -v grep | awk '{print $1}'`
Related videos on Youtube
Author by
Trindaz
Updated on September 18, 2022Comments
-
Trindaz over 1 year
I'm running a Python application that spawns multiple processes. It uses port 56008 to listen for client requests. Sometimes after closing it the port it used is still "in use". There are still some python processes that appear to be running but trying to kill them using
kill
doesn't seem to have any affect.How can I free it up manually so I can restart my application?
More info:
Output of
ps -C python
PID TTY TIME CMD 30118 pts/1 00:00:00 python 30131 pts/1 00:00:00 python
*There are about 30 lines in total of the format
[pid] pts/1 00:00:00 python
Output of
netstat -tulp
(relevant line only):Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 *:56008 *:* LISTEN -
-
David Schwartz almost 11 yearsThere are no other lines that refer to port 56008? Are you 100% sure?
-
-
Falcon Momot almost 11 yearsYou could probably simplify that substantially to
killall -9 python
, unless things which called python because python was in their arguments are also stuck. It's interesting, nonetheless, that netstat didn't report python as owning the socket. -
Trindaz almost 11 years@Falcon Very - I think it's related to them being sub-processes, and the fact that the parent process had died.
-
Flup almost 11 yearsMaybe
netstat
wasn't run as root or the owner of the processes. -
Falcon Momot almost 11 yearsThat seems more likely.
-
Trindaz almost 11 years@Flup good point - the app was started using sudo and I wasn't logged in as root when running netstat.