Mutual query between Linux port number and PID

Source: Internet
Author: User

Mutual query between Linux port number and PID

 

Recently I used Linux to play with Tomcat. When I started it, I always reported an error (8080/8009/8005). So I sorted out the PID and port commands on the Internet for record.

 

1. query the PID Number by the port number

 

First, when myeclipse reports an error, it will prompt: "port 8009 is occupied", so you have to check which processes are running under this port based on this port

 

Run the following command to view all ports running on the current system: sudo netstat-antup

 

Note: Check the sudo permission. Otherwise, some PIDs cannot be viewed. I used to go around a lot because I didn't use the root permission.

 

2. query the port number with PID

 

If you know the process PID, how can you view the process status of the PID?

 

Run the command: sudo netstat-antup | grep PID to query the opening status of the target port! The premise is that you need to know the PID Number:

 

Is to use PID 1024 to view the port, we can see that the port is in the LISTEN listening status, and the port is 80.

 

3. query the PID number with the process name

 

Sometimes we are familiar with some common processes, so we can use the ps command to query the target PID:

 

Run the command: sudo ps-ef | grep process name to view the PID of the process. But the premise is that you need to know the name of the process, for example, some background processes cannot be viewed.

 

Use this command to check that the PID of the mysql database is 2807 and the port number is 3306.

 

 

 

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.