1

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

Jess
  • 389
  • 1
  • 6
  • 16

2 Answers2

1

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 
dmourati
  • 25,540
  • 2
  • 42
  • 72
1

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.

quanta
  • 51,413
  • 19
  • 159
  • 217