본문 바로가기

공부/Linux

Port로 PID 찾기

현재 사용하고 있는 port를 어떤 프로세스가 사용하고 있는지 확인하는 명령이다.

 

lsof -i:PORT번호

 

위와 같은 명령을 통해 검색 가능하다.

아래는 MySQL에서 사용하고 있는 모든 port의 PID를 검색하는 스크립트이다.

 

#!/bin/sh
PORTS=`mysql -uroot -pmegaroot -N information_schema -e "select substr(host,locate(':',host)+1) from information_schema.processlist where locate(':',host)!=0"`
for i in $PORTS
do
lsof -i:$i
done;
반응형

'공부 > Linux' 카테고리의 다른 글

CentOS7에서 jar파일 systemd service에 등록하기  (0) 2019.05.28