All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.commons.jdkspecific.ProcessInfo Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev04
Show newest version
package org.infinispan.commons.jdkspecific;

import java.util.Arrays;
import java.util.List;

/**
 * @author Tristan Tarrant <[email protected]>
 * @since 11.0
 **/
public class ProcessInfo {
   private final String name;
   private final long pid;
   private final long ppid;
   private final List arguments;

   private ProcessInfo(ProcessHandle handle) {
      name = handle.info().command().orElse("-");
      pid = handle.pid();
      ppid = handle.parent().map(ProcessHandle::pid).orElse(-1l);
      arguments = Arrays.asList(handle.info().arguments().orElse(new String[]{}));
   }

   public static ProcessInfo getInstance() {
      return new ProcessInfo(ProcessHandle.current());
   }

   public static ProcessInfo of(Process process) {
      return new ProcessInfo(process.toHandle());
   }

   public String getName() {
      return name;
   }

   public long getPid() {
      return pid;
   }

   public List getArguments() {
      return arguments;
   }

   public ProcessInfo getParent() {
      if (ppid > 0) {
         return new ProcessInfo(ProcessHandle.of(ppid).get());
      } else {
         return null;
      }
   }

   @Override
   public String toString() {
      return "Process[jdk11]{" +
            "name='" + name + '\'' +
            ", pid=" + pid +
            ", ppid=" + ppid +
            ", arguments=" + arguments +
            '}';
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy