Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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      -
share|improve this question
There are no other lines that refer to port 56008? Are you 100% sure? – David Schwartz Jun 26 '13 at 7:54

This did the trick

sudo kill -9 `ps -C python | grep python | grep -v grep | awk '{print $1}'`
share|improve this answer
You 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. – Falcon Momot Jun 26 '13 at 7:56
@Falcon Very - I think it's related to them being sub-processes, and the fact that the parent process had died. – Trindaz Jun 26 '13 at 7:57
Maybe netstat wasn't run as root or the owner of the processes. – Flup Jun 26 '13 at 7:58
That seems more likely. – Falcon Momot Jun 26 '13 at 8:00
@Flup good point - the app was started using sudo and I wasn't logged in as root when running netstat. – Trindaz Jun 26 '13 at 22:13

You may try and code properly how your application will exit (e.g. kill all children, close network sockets)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.