DEV Community

Xun Zhou
Xun Zhou

Posted on

find the processes which are listening to a port on MacOS

Sometimes, we couldn't start a docker service, because the configured port was used by another process. To find out which process is using this port.
We can simply create an (zsh) alias as following:

# ~/.zshrc
alias port='lsof -i -P | grep LISTEN | grep $1'
Enter fullscreen mode Exit fullscreen mode

Then just use this alias port <number> to find the running process on port 8080:

➜  ~
❯ port 8080
node      10126 zhouxun   25u  IPv4 0x83e36c82e2c8dccb      0t0  TCP *:8080 (LISTEN)
Enter fullscreen mode Exit fullscreen mode

We found the process with PID 10126 and it was a node process.

Then we can kill the process by using(if needed, use sudo):

➜  ~
❯ kill -9 10126
Enter fullscreen mode Exit fullscreen mode

Top comments (0)