Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a server running on a local server. Every once in a while it will freeze up, and I'll need to use a Ctrl+Z to cancel out of it. The issue is that the port it uses is still open to it after I force close it, and it can't reclaim that port when I restart the program. So then I need to restart the entire server.

Is there a way I could force that port closed, so the service could open it when it starts back up, or maybe refresh all the ports?

Thanks,
max

share|improve this question
    
Did you write this program? This is a program bug, most likely failing to set SO_REUSEPORT. –  David Schwartz Oct 15 '11 at 3:06

2 Answers 2

up vote 1 down vote accepted

ctrl-z is a suspend.

You probably want ctrl-c.

You can also send a signal to the individual PID. For example, if I wanted to close port 80, I could first query open files with lsof:

lsof -i tcp:80

httpd 24579 root 3u IPv6 142712111 TCP *:http (LISTEN)

Then send a kill signal:

kill -9   24579 
share|improve this answer
    
That's what I was looking for, thanks! –  mazzzzz Oct 15 '11 at 3:13

Ctrl+Z is only suspend your job, place it in the backgroud, so the port is still open. Just use Ctrl+C instead.

In your case, find out the process which is listening on this port with:

# netstat --protocol=ip -nlp | grep :port

and kill the PID. No need to reboot the server.

share|improve this answer

Your Answer

 
discard

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.