2 the process of finding the port number
3 found the process id.
4 kill it
This program can be completed bit by bit:
1 View services that occupy port numbers.
[root@aslibra root]# netstat -nlp
Active Internet connection (server only)
Proto Recv-Q Send-Q local address external address status PID/ program name
TCP 0 0 0 0 0 0 0:3306 0 0 0 0 0:* List EN 23946/
TCP 0 0 0 0 0 0 0:3307 0 0 0 0 0:* List EN 127 1 1/
TCP 0 0 0 0 0 0 0 0:80 0 0 0 0 0:* List EN 3936/stat -nlp | grep :3306
TCP 0 0 0 0 0 0 0:3306 0 0 0 0 0:* List EN 23946/
Now take out one line and it will be easy. Filter it again, divide it with awk, and take out one of them.
3 Read out the port number
[root @ as Libra root]# netstat-NLP | grep:3306 | awk“{ print $ 7 }”
23946/
It means to take the seventh field, which is separated by tabs by default. I have read it out, but I still have to get it before the number/
4 Just take the number before/,and you can still use awk here.
[root @ as Libra root]# netstat-NLP | grep:3306 | awk“{ print $ 7 }”| awk-F "/“{ print $ 1 }”
23946
It means to divide/sign, and take the first part.
Then pass this number to kill.
The kill command cannot continue processing after the pipe symbol, it will cause an error.
[root @ as Libra root]# netstat-NLP | grep:3306 | awk“{ print $ 7 }”| awk-F "/“{ print $ 1 }”| kill
Kill: usage: kill [-s sigspec |-n signum |-sigspec] [PID | job] ... or kill -l [sigspec]
Need to use the "[']" operator, it can execute a statement, this statement can be executed like this:
kill[']netstat-NLP | grep:3306 | awk“{ print $ 7 }”| awk-F "/“{ print $ 1 }”[']