How to find a process through a connected port

Source: Internet
Author: User

The company's cache system has problems these days, the number of connections exceeds the limit 2048 , which causes the application to not continue to work, we need to determine which process has a high number of connections, as follows:

  1. Find the port number of the application that is connecting to the cache server

    assuming that the port number of the cache server is 11111,

    #netstat –an |grep 11111 Find the application port number of the connection cache server

    TCP 0 0 xx.xx.xx.xa.52878 xx.xx.xx.xb.11111 established

    TCP 0 0 xx.xx.xx.xa.52968 xx.xx.xx.xb.11111 established

    TCP 0 0 xx.xx.xx.xa.52952 xx.xx.xx.xb.11111 established

    TCP 0 0 xx.xx.xx.xa.52876 xx.xx.xx.xb.11111 established

    TCP 0 0 xx.xx.xx.xa.52852 xx.xx.xx.xb.11111 established

    ......

    the port number of the connection cache system is 52878,52968,52962,52876,52852,... , these port numbers are very numerous and have thousands of records.

    #netstat –an|grep 11111 |awk ' {print $4} ' >/tmp/netlog.txt extract these port numbers

    xx.xx.xx.xa.52878

    xx.xx.xx.xa.52968

    xx.xx.xx.xa.52952

    xx.xx.xx.xa.52876

    xx.xx.xx.xa.52852

    ......

    #vi/tmp/netlog.txt Open the /tmp/netlog.txt file using the vi editor , delete the /c7>IP address

    : 1, $s/^.\{12\}//g input in non-edit mode, preceded by a space substitution for the first three characters of the IP

    after editing is complete , the NetLog.txt file is left with only the port number.

  2. Find out which process the port number corresponds to

    #vi/tmp/netlog.sh scan The port number of the NetLog.txt file by line and execute the lsof command

For line in $ (cat/tmp/netlog.txt)

Do

echo "File:${line}"

Lsof–f P-i:${line}

Done

#/tmp/netlog.sh >/tmp/netout.txt executes the script file and outputs it.

#cat/tmp/netout.txt View the file to find the process number for the port

P2997

P2997

P2997

P1887

P2997

......

2997 and the 1887 is the process number, 2997 high frequency, the process connection cache more.

#ps –ef |grep2997 View the process program


This article is from "Yao XI" blog, please be sure to keep this source http://huriver.blog.51cto.com/2745601/1642153

How to find a process through a connected port

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.