Shell: Identify process using a given port number
source link: https://proinsias.github.io/til/shell-identify-process-using-a-given-port-number/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Francis T. O'Donovan
Senior Data Science Manager at Hospital IQ – Planet discoverer, researcher, developer, geek.
Shell: Identify process using a given port number
less than 1 minute read
Say you want to run an command that uses a given port number (e.g., TCP 3032), and it complains that that port number is already in use. In order to identify what command is using that port number, run the following command:
> lsof -iTCP:3032
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
com.docke 5545 ftod 3u IPv6 0x238ae01b5cc3b65b 0t0 TCP *:redwood-chat (LISTEN)
com.docke 5545 ftod 225u IPv6 0x238ae01b5f23595b 0t0 TCP localhost:redwood-chat->localhost:50157 (FIN_WAIT_2)
...
If there are multiple results, you may want to filter to find the commands listening to that port:
> lsof -iTCP:3032 | grep LISTEN
com.docke 5545 ftod 3u IPv6 0x238ae01b5cc3b65b 0t0 TCP *:redwood-chat (LISTEN)
If necessary, you can then use kill
with the process identification number (PID) associated with that command.
Categories: til
Updated: June 28, 2022
You May Also Enjoy
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK