datastuffplus

Datastuffplus started as a development instagram blog and still is.

Member-only story

Is there a way to taskkill all process ID’s that are using a specific port?

Kyle Pastor
datastuffplus
Published in
2 min readFeb 17, 2023

--

Photo by Onur Binay on Unsplash

During my coding life I have had some issues with port’s not unbinding when a task was supposed to finish. To solve this I asked ChatGPT to give me a one liner to kill all tasks that are using a specific port. Here is what I got:

Yes, you can use the command line to taskkill all process IDs that are using a specific port. Here are the steps:

Open the command prompt as an administrator.

Type the following command to find the process IDs (PIDs) that are using the specific port. Replace [port_number] with the port number you want to check:

netstat -ano | findstr :[port_number]

This command will display a list of all the processes that are using the specified port, along with their PIDs.

Use the taskkill command to terminate the processes using the PIDs you found in step 2. Replace [PID] with the PID of the process you want to terminate:

taskkill /F /PID [PID]

You can repeat this command for each PID that is using the specified port until all of the processes are terminated.

Alternatively, you can use a single command that combines steps 2 and 3:

for /f "tokens=5" %a in ('netstat -ano ^| findstr :[port_number]') do taskkill /f /pid %a

This command will find all processes using the specified port and automatically terminate them. Note that you should replace [port_number] with the actual port number you want to check.

--

--

datastuffplus
datastuffplus

Published in datastuffplus

Datastuffplus started as a development instagram blog and still is.

Kyle Pastor
Kyle Pastor

Written by Kyle Pastor

Analytics | Full Stack | Data Science | MS Physics + MS Quant Finance → http://kapastor.github.io/

No responses yet