[Terminal] Finding port availability and killing process using it

To find out if there are any processes using a particular port, you should run the following command line:
lsof -n -i4TCP:<PORT NUMBER>
which will give you the following:


Then, enter the following cl to kill the process:
kill -9 <PID>


More Info

lsof:

  • means list open files
  • lists file information about files opened by particular process(es)ers to host names for network files. 
  • -n option makes the command faster by preventing it from doing an IP to hostname conversion.
  • -i[internet address] option selects the listing of files whose internet address matches the internet address. 
  • Internet address format: 
    • [4 or 6][protocol][@hostname | hostaddr][:service | port]
      • The 4 or 6 refers to IPv4 and IPv6



Resources:
https://stackoverflow.com/questions/3855127/find-and-kill-process-locking-port-3000-on-mac

Comments

Popular posts from this blog

[Redis] Redis Cluster vs Redis Sentinel

[Unit Testing] Test Doubles (Stubs, Mocks....etc)

[Node.js] Pending HTTP requests lead to unresponsive nodeJS