Find and Kill a Process

Find and Kill a Process

2021-10-09. Category & Tags: Windows, Linux, Commands, Networking, Ports

see also: 鸟哥 Linux 私房菜 Basic Linux.

Linux #

find bound PID by port: fuser 8080/tcp kill by port: fuser -k 8080/tcp list by port: lsof -i:8080

using new ss -tulpn |grep 8080 ss -tulpn 'sport = :8080' old: netstat -tulvpn |grep :8080

then: ps auxf | grep the_pid

ref 1 & ref 2

Windows #

CMD find PID by port & kill by PID:

:: find pid first:
netstat -ano | findstr :8080
:: then the pid's task/process
tasklist | findstr "<the_PID>"
taskkill /PID <the_PID> /F

PS find for TCP & UDP:

Get-Process -Id (Get-NetTCPConnection -LocalPort <port_number>).OwningProcess
Get-Process -Id (Get-NetUDPEndpoint -LocalPort <port_number>).OwningProcess

xxx cmd list all:netstat -a -b

ref