To view a process shutdown port using a port

Source: Internet
Author: User

To view a process that uses a port

The simplest commands are:

-i :端口号
    • 1

If you want to use Administrator privileges then it is:

sudo lsof -i :端口号
    • 1

So looking at a process using a port number 3000 can be used:

lsof -i :3000
    • 1

You can also use:

sudo lsof -i :3000
    • 1

The results of the terminal are as follows:

HarveydeMac-mini:~ harvey$ sudo lsof -i :3000COMMAND   PID   USER   FD   TYPE            DEVICE SIZE/OFF NODE NAMEnode    20771 harvey 17u IPv4 0x56e527dafba04d5 0t0 TCP *:hbci (LISTEN)
    • 1
    • 2
    • 3

COMMANDRepresents the name of the process using the port, which is clearly the 3000 port used by node.
PIDMore critical, representing the process number that uses the port.
(LISTEN)Indicates that the process is in a listening state, that is, the process is active.

sudo lsof -i tcp:3000
    • 1

The execution result is the same as the previous command.

There are also some optional parameters on the above command, which are then derived in addition to a scoop command. It can also be used to check the process of using a port.

Like what:

sudo lsof -i :3000 | grep LISTEN
    • 1

Execution Result:

HarveydeMac-mini:~ harvey$ sudo lsof -i :3000 | grep LISTENnode 20771 harvey 17u IPv4 0x56e527dafba04d5 0t0 TCP *:hbci (LISTEN)
    • 1
    • 2

And:

sudo lsof -i tcp:3000 | grep LISTEN
    • 1

The execution result is the same as the previous command.

command to close a process

To close a process that uses a port:

sudo kill -9 PID
    • 1

For example, I turned off the node process using port 3000

sudo kill -9 20771
    • 1

Of course, we can also disable the process by not applying administrator privileges

kill -9 20771

To view a process shutdown port using a 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.