I didn't know how to drop the server when I launched the app on the built-in server of Spring Boot, so I wrote a shell. Kill the process using the port in java. Adding a port number to the parameter will delete the process on the specified port, otherwise it will delete all processes using the port.
code
#!/bin/bash
#Parameters:port number
port=$1
#Get the process ID of java
lines=($(lsof -i -P | grep "java.*${port}.*LISTEN" | awk '{print $2}'))
#Kill the process ID obtained by lines
for i in ${lines[@]}
do
kill ${i}
ret=$?
if [ ! $ret -eq 0 ]; then
exit 1
fi
done
exit 0
reference: How to find out which port is used as LISTEN on mac
Recommended Posts