How to Kill service running on port using terminal command


If you want to use a certain port to run some application on your Unix/Linux based system such as macOS but you get "Address/Port already in use" error and you don't have access to stop the service then you can kill this process as follows,

  1. Open Terminal.
  2. Run the command with the port used : example : lsof -i : <port_number>.
  3. You will get an output with ProcessID - PID if some process is running on it..
  4. COMMAND PID  USER   FD   TYPE      DEVICE        SIZE/OFF  NODE NAME
    java    4133 code2care   13u  IPv6 0x335aaef2sdf      0t0  TCP *:a39c892 (LISTEN)
  5. Now kill the process by running the following command : kill -9 <PID> (example : kill -9 4133)..
  6. Now try to run the server you would not get BindException exception..
Know all services running on ports macOS
Know all services running on ports macOS

To know which services are running on which port you can do a port scan on a Mac device as follows:

  1. Open Network Utility (using Spotlight Search)
  2. Go to Post Scan tab
  3. If the services are running on localhost Enter IP as localhost or 127.0.0.1
  4. You can run the test for all ports or certain range say 80 to 10000
Port Scan has started…

Port Scanning host: 127.0.0.1

	 Open TCP Port: 	80     		http
	 Open TCP Port: 	88     		kerberos
	 Open TCP Port: 	443    		https
	 Open TCP Port: 	631    		ipp
	 Open TCP Port: 	3306   		mysql

Port Scan has completed…


















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap