パッケージ com.kazurayam.subprocessj

クラス ProcessTerminator


  • public class ProcessTerminator
    extends java.lang.Object
    killProcessListeningPort(int portNumber) identifies the running process that is listening the IP port #portNumber, get the Process ID, then kill the process. I want this class to run on Java 8. Therefore I can not rely on the `long pid()` method of `java.lang.Process` which was added at Java 9. So I will use `lsof -i:portNumber -P` command on Mac on Windows? TODO later
    • コンストラクタの詳細

      • ProcessTerminator

        public ProcessTerminator()
    • メソッドの詳細

      • killProcessOnPort

        public static ProcessTerminator.ProcessTerminationResult killProcessOnPort​(int portNumber)
                                                                            throws java.io.IOException,
                                                                                   java.lang.InterruptedException
        パラメータ:
        portNumber - the IP port number on which the Process is hanging on; you want to kill that process.
        戻り値:
        the ID of the process (>0) which is listening to the IP portNumber and therefore killed; returns -1 if the process was not found.
        例外:
        java.io.IOException - if failed to kill a OS process
        java.lang.InterruptedException - if the process was interrupted
      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.IOException,
                                java.lang.InterruptedException
        例外:
        java.io.IOException
        java.lang.InterruptedException