Kill the process and start the application based on the port number in linux.

Source: Internet
Author: User
In linux, kill the process based on the port number and start the application-Linux Enterprise Application-Linux server application information. The following is a detailed description. 1. A process determines to occupy a tcp port. The following command can kill the process.

Kill-9 $ (netstat-tlnp | grep 1099 | awk '{print $7}' | awk-F'/''{print $1 }')

1099 indicates the port number. Note:

Write the complete port number, otherwise it is easy to kill other processes by mistake. 7 is the column number of the process information. It may vary with Linux and needs to be adjusted.

2. The two applications service1 and service2 depend on service1, that is, service1 can be started only after it is started. If the service1 application occupies a specified tcp port, the following script can perform this operation:

Echo "service1 start ..."
./Service1.sh

Netstat-tlnp | grep 2098
Until ["$? "-Eq" 0 "]
Do
Echo "waiting service1 to startup ..."
Sleep 1
Netstat-tlnp | grep 2098
Done
Echo "service1 started ."
./Service2.sh
Echo "service2 started ."

2098 is the tcp port occupied by service1.
Related Article

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.