How do I close an open port from the terminal on the Mac?

223

I opened port #5955 from a java class to comunicate from a client. How do i close this port after I am done? and also which command can show me if port open or closed?

This question is tagged with macos port

~ Asked on 2012-09-12 22:50:45

The Best Answer is


437

  1. Find out the process ID (PID) which is occupying the port number (e.g., 5955) you would like to free

    sudo lsof -i :5955
    
  2. Kill the process which is currently using the port using its PID

    sudo kill -9 PID
    

~ Answered on 2013-07-17 14:48:05


58

To find the process try:

sudo lsof -i :portNumber

Kill the process which is currently using the port using its PID

kill PID

and then check to see if the port closed. If not, try:

kill -9 PID

I would only do the following if the previous didnt work

sudo kill -9 PID

Just to be safe. Again depending on how you opened the port, this may not matter.

~ Answered on 2015-10-06 05:55:14


Most Viewed Questions: