Terminate Process on a Port from Command Line

Once a week I have to deal with a zombie process or try to start a process that’s already running on its designated port. In most cases I use macOS’s Activity Monitor to kill the process, which is time-consuming. What if we could just kill a process on a given port from command line? Well, […]

The post Terminate Process on a Port from Command Line appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh

Once a week I have to deal with a zombie process or try to start a process that’s already running on its designated port. In most cases I use macOS’s Activity Monitor to kill the process, which is time-consuming. What if we could just kill a process on a given port from command line? Well, we can!

To terminate a process on a given port, install kill-port and starting nuking those zombies via:

# yarn global add kill-port

# Kill processes on multiple ports
kill-port 6060 8000

If you want to programmatically kill a port that you want to ensure your app will run on, you can do that as well:

const kill = require('kill-port')

kill(6060, 'tcp')
      .then(console.log)
      .catch(console.log)

I look forward to incorporating this library into my Node.js sites so that I can clear the way for a given port and avoid zombie processes.

The post Terminate Process on a Port from Command Line appeared first on David Walsh Blog.


This content originally appeared on David Walsh Blog and was authored by David Walsh


Print Share Comment Cite Upload Translate Updates
APA

David Walsh | Sciencx (2021-10-10T17:42:32+00:00) Terminate Process on a Port from Command Line. Retrieved from https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/

MLA
" » Terminate Process on a Port from Command Line." David Walsh | Sciencx - Sunday October 10, 2021, https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/
HARVARD
David Walsh | Sciencx Sunday October 10, 2021 » Terminate Process on a Port from Command Line., viewed ,<https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/>
VANCOUVER
David Walsh | Sciencx - » Terminate Process on a Port from Command Line. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/
CHICAGO
" » Terminate Process on a Port from Command Line." David Walsh | Sciencx - Accessed . https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/
IEEE
" » Terminate Process on a Port from Command Line." David Walsh | Sciencx [Online]. Available: https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/. [Accessed: ]
rf:citation
» Terminate Process on a Port from Command Line | David Walsh | Sciencx | https://www.scien.cx/2021/10/10/terminate-process-on-a-port-from-command-line/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.