Find process running on port: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
Line 1: Line 1:
== Commands ==
== Find process running on port in Windows ==
* {{Win}} {{kbd | key=<nowiki>netstat –na | find "<PORT>"</nowiki>}} e.g. {{kbd | key=<nowiki>netstat –na | find "4444"</nowiki>}} or {{kbd | key = <nowiki>netstat -a | find "3306"</nowiki>}} (note: require the '''double quote''' symbol, not single quote symbol) for {{Win}}<ref>[http://technet.microsoft.com/en-us/library/bb490947.aspx Netstat]</ref>  
* GUI software: [https://www.nirsoft.net/utils/cports.html CurrPorts: Monitoring TCP/IP network connections on Windows]
* GUI software: [https://docs.microsoft.com/zh-tw/sysinternals/downloads/tcpview Windows 的 TCPView - Windows Sysinternals | Microsoft Docs]
* Command: {{kbd | key=<nowiki>netstat –na | find "<PORT>"</nowiki>}} e.g. {{kbd | key=<nowiki>netstat –na | find "4444"</nowiki>}} or {{kbd | key = <nowiki>netstat -a | find "3306"</nowiki>}} (note: require the '''double quote''' symbol, not single quote symbol) for {{Win}}<ref>[http://technet.microsoft.com/en-us/library/bb490947.aspx Netstat]</ref>  
* Command to kill: [https://www.npmjs.com/package/kill-port kill-port - npm]
 
== Find process running on port in Mac ==
* {{Mac}}  
* {{Mac}}  
** {{kbd | key=<nowiki>netstat -vanp tcp | grep 4444</nowiki>}} or  
** {{kbd | key=<nowiki>netstat -vanp tcp | grep 4444</nowiki>}} or  
** {{kbd | key=<nowiki>lsof -i tcp:4444</nowiki>}} or {{kbd | key=<nowiki>lsof -i :4444</nowiki>}}<ref>[https://man7.org/linux/man-pages/man8/lsof.8.html lsof(8) - Linux manual page]</ref>
** {{kbd | key=<nowiki>lsof -i tcp:4444</nowiki>}} or {{kbd | key=<nowiki>lsof -i :4444</nowiki>}}<ref>[https://man7.org/linux/man-pages/man8/lsof.8.html lsof(8) - Linux manual page]</ref>
** {{kbd | key=<nowiki>sudo lsof -i -P | grep LISTEN | grep :$PORT</nowiki>}}<ref>[https://stackoverflow.com/questions/4421633/who-is-listening-on-a-given-tcp-port-on-mac-os-x macos - Who is listening on a given TCP port on Mac OS X? - Stack Overflow]</ref>
** {{kbd | key=<nowiki>sudo lsof -i -P | grep LISTEN | grep :$PORT</nowiki>}}<ref>[https://stackoverflow.com/questions/4421633/who-is-listening-on-a-given-tcp-port-on-mac-os-x macos - Who is listening on a given TCP port on Mac OS X? - Stack Overflow]</ref>
== Find process running on port in Windows ==
* {{Linux}} CentOS7:  
* {{Linux}} CentOS7:  
** {{kbd | key=<nowiki>netstat -na | grep ":<port>"</nowiki>}} e.g. {{kbd | key=<nowiki>sudo netstat -pan | grep ":80"</nowiki>}} or  
** {{kbd | key=<nowiki>netstat -na | grep ":<port>"</nowiki>}} e.g. {{kbd | key=<nowiki>sudo netstat -pan | grep ":80"</nowiki>}} or  

Revision as of 16:17, 10 May 2022

Find process running on port in Windows

Find process running on port in Mac

  • macOS icon_os_mac.png
    • netstat -vanp tcp | grep 4444 or
    • lsof -i tcp:4444 or lsof -i :4444[2]
    • sudo lsof -i -P | grep LISTEN | grep :$PORT[3]

Find process running on port in Windows

  • Linux Os linux.png CentOS7:
    • netstat -na | grep ":<port>" e.g. sudo netstat -pan | grep ":80" or
    • ps -elf | grep <port>
## windows
## After running process on windows, and then input the command: netstat –na | find "4444"
  TCP    0.0.0.0:4444           0.0.0.0:0              LISTENING
  TCP    [::]:4444              [::]:0                 LISTENING

## mac
## After running process on mac, and then input the command: netstat -vanp tcp | grep 4444
tcp46      0      0  *.4444                 *.*                    LISTEN      131072 131072  15476      0 0x0000 0x00000006
tcp4       0      0  127.0.0.1.54419        127.0.0.1.4444         TIME_WAIT   408300 146988  15476      0 0x2031 0x00000000

## mac
## After running process on mac, and then input the command: lsof -i tcp:4444
COMMAND   PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java    15476 user    8u  IPv6 0x8eb77926a50f8a53      0t0  TCP *:krb524 (LISTEN)

## Liunx
## After running process on mac, and then input the command: sudo netstat -pan | grep ":80"
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      23370/python3
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      23025/nginx: master
tcp6       0      0 :::80                   :::*                    LISTEN      23025/nginx: master
tcp6       0      0 :::8000                 :::*                    LISTEN      22001/docker-proxy  

問題排除

FIND: 參數格式不正確

問題: Win Os windows.png netstat –na | find 4444 輸入後遇到「FIND: 參數格式不正確」錯誤訊息。

解決方式: 請將 <port> 加上雙引號,例如: netstat –na | find "4444"


相關資料

參考資料