How to Kill Processes and Free Up Ports on Mac, Windows and Linux

When a computer has too many processes running at once, it can slow down the computer. Here’s how to find and kill running processes on macOS, Windows and Linux  

Written by Aditya Rawas
Published on Dec. 16, 2024
Sysadmin working on computer
Image: Shutterstock / Built In
Brand Studio Logo

Have you ever encountered a situation where you needed to free up a port on your system but found it stubbornly held by a process? A process is a currently running program or application. When they aren’t properly managed, they can slow down your system. 

2 Steps to Kill a Process and Open a Port on MacOs

  1. Find the process ID (PID):
    sudo lsof -i :portNumber
  2. Kill the process:
    kill PID

Whether you’re on Mac, Windows or Linux, here’s a guide to gracefully handle this common issue.

 

How to Kill a Process to Open a Port on Mac OS

1. Find the Process ID (PID)

sudo lsof -i :portNumber

Replace portNumber with the actual port number. Copy the PID number.

2. Kill the Process

kill PID

Replace PID with the copied process ID. If necessary, try kill -9 PID or sudo kill -9 PID for forceful termination.

A tutorial on how to kill a process in macOS. | Video: OnTech

More on Software EngineeringHow to Configure C++ Formatting in Visual Studio Code

 

How to Kill a Process to Open a Port on Windows

1.  Find the Process ID (PID)

netstat -ano | findstr :portNumber

Replace portNumber with the port number. Copy the PID number.

2. Kill the Process

taskkill /PID typeyourPIDhere /F

Replace typeyourPIDhere with the copied PID. Recheck using the first command.

More on Software EngineeringLinux cp Command: How to Copy a File or Directory

 

How to Kill Processes in Linux

1. Get a List of All Open Processes

top

2. Kill a Process

kill pid

Use killall pname to kill by name. Add -9 for forceful killing. Use sudo if needed.

Remember, terminating processes forcefully (-9) should be a last resort as it can cause data loss or system instability. Always try graceful termination (kill) first.

By following these steps tailored to your operating system, you can efficiently manage and free up ports, ensuring smooth operation for your applications. Whether you’re a developer, system administrator or a curious user, mastering these techniques can save you time and frustration.

Frequently Asked Questions

  1. macOS: kill pid
  2. Windows: taskkill /PID typeyourPIDhere /F
  3. Linux: kill pid or killall pname

If you want to forcefully terminate a process, you can enter -9 to the kill pid command. This should be used as a last resort, as it can cause data loss or system instability. 

Explore Job Matches.