This is the ninth day of my participation in the August More text Challenge. For details, see: August More Text Challenge

While the service is running, we often have to look at the entire server port and process occupancy, and even interrupt the process if necessary. Today’s article summarizes a few commands that have been helpful to us.

1, lsof(list open files)

The lsof tool can be used to view the list of descriptors of the files opened by the application program, which can provide considerable help for system monitoring and troubleshooting.

Lsof -i :portNumber Lists who is using a certain portCopy the code

Second, the netstat

The netstate command is used to display various network information, such as network connections, routing tables, Interface Statistics, Masquerade connections, Multicast Memberships, and so on.

Common parameters

parameter instructions
-a (all) Displays all options, with no LISTen-related options displayed by default
-t (tcp) Only TCP related options are displayed
-u (udp) Only UDP related options are displayed
-n Refuse to display aliases that can display all numbers converted into numbers
-l Refuse to display aliases that can display all numbers converted into numbers
-p Displays the name of the program that created the related link
-r Display routing information and routing table
-e Display extended information, such as uid
-s Statistics are collected by protocol
-c Run the netstat command at a fixed interval
Netstat anp | grep portNumber view takes up the process of a portCopy the code

Three, ps

The ps command is used to report the process status of the current system. The kill directive can be used to interrupt and delete unnecessary programs at any time. A very powerful process view command that can be used to determine which processes are running and what their status is, whether they are dead, whether they are dead, which processes are taking up too many resources, and so on

ps -ef |grep ssh
Copy the code

Fourth, the kill

Common parameters

-a: The mapping between command names and process ids is not restricted when the current process is processed. -l < Information number > : If the < information number > option is not added, the -l parameter lists all information names. -p: When the kill command is used, only the process number of related processes is printed, but no signal is sent. -s < Message name or number > : Specifies the message to be sent. -u: specifies a user.Copy the code
Kill -l Lists all signal names. Only the ninth signal (SIGKILL) can terminate the process unconditionally. Kill -9 PID Completely kills the specified processCopy the code