Shell to kill Java process

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.



#Parameters:port number

#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[@]}
  kill ${i}
  if [ ! $ret -eq 0 ]; then
    exit 1

exit 0

reference: How to find out which port is used as LISTEN on mac

Recommended Posts

Shell to kill Java process
[Java] Input to stdin of Process
Java buffering process
Java check process
[Java] Introduction to Java
Introduction to java
Changes from Java 8 to Java 11
Sum from Java_1 to 100
Kotlin's improvements to Java
From Java to Ruby !!
Introduction to java command
[Java] Change the process according to the situation with the Strategy pattern
[Java] How to use Map
How to lower java version
Migration from Cobol to JAVA
[Java] How to use Map
Convert Java Powerpoint to XPS
Java adds table to PDF
How to uninstall Java 8 (Mac)
Java to play with Function
Java --How to make JTable
How to use java Optional
New features from Java7 to Java8
How to minimize Java images
How to write java comments
[Implementation] Java Process class notes
How to use java class
[Java] How to use Optional ②
Connect from Java to PostgreSQL
[Java] How to use removeAll ()
[Java] How to display Wingdings
[Java] Introduction to lambda expressions
[Java] How to use string.format
How to use Java Map
How to set Java constants
Connect to DB with Java
Connect to MySQL 8 with Java
[java] Reasons to use static
How to use Java variables
[Java] Introduction to Stream API
Java8 to start now ~ Optional ~
How to convert Java radix
External process execution in Java
[Java] Convert ArrayList to array
Java thread to understand loosely
[Java] How to implement multithreading
[Java] How to use Optional ①
From Ineffective Java to Effective Java
How to initialize Java array
[Introduction to rock-paper-scissors games] Java
Input to the Java console
"Wait for the process to finish." And kill the process because it remains.
Add multi-letter watermark to Java Word
How to study Java Silver SE 8
How to use Java HttpClient (Get)
Operation to connect multiple Streams @Java
Java to learn with ramen [Part 1]
Studying Java # 6 (How to write blocks)
[Introduction to Java] About lambda expressions
[java8] To understand the Stream API
Multithreaded to fit in [Java] template