Package ai.libs.jaicore.processes
Class ProcessUtil
- java.lang.Object
-
- ai.libs.jaicore.processes.ProcessUtil
-
public class ProcessUtil extends java.lang.Object
The process util provides convenient methods for securely killing processes of the operating system. For instance, this is useful whenever sub-processes are spawned and shall be killed reliably.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static EOperatingSystem
getOS()
Retrieves the type of operating system.static int
getPID(java.lang.Process process)
Gets the operating system's process id of the given process.static java.lang.Process
getProcessListProcess()
Gets the OS process for the process list.static java.util.Collection<ProcessInfo>
getRunningJavaProcesses()
Gets a list of running java processes.static void
killProcess(int pid)
Kills the process with the given process id.static void
killProcess(java.lang.Process process)
Kills the provided process with a operating system's kill command.
-
-
-
Method Detail
-
getOS
public static EOperatingSystem getOS()
Retrieves the type of operating system.- Returns:
- Returns the name of the operating system.
-
getProcessListProcess
public static java.lang.Process getProcessListProcess() throws java.io.IOException
Gets the OS process for the process list.- Returns:
- The process for the process list.
- Throws:
java.io.IOException
- Thrown if a problem occurred while trying to access the process list process.
-
getRunningJavaProcesses
public static java.util.Collection<ProcessInfo> getRunningJavaProcesses() throws java.io.IOException
Gets a list of running java processes.- Returns:
- The list of running Java processes.
- Throws:
java.io.IOException
- Throwsn if there was an issue accessing the OS's process list.
-
getPID
public static int getPID(java.lang.Process process) throws ProcessIDNotRetrievableException
Gets the operating system's process id of the given process.- Parameters:
process
- The process for which the process id shall be looked up.- Returns:
- The process id of the given process.
- Throws:
ProcessIDNotRetrievableException
- Thrown if the process id cannot be retrieved.
-
killProcess
public static void killProcess(int pid) throws java.io.IOException
Kills the process with the given process id.- Parameters:
pid
- The id of the process which is to be killed.- Throws:
java.io.IOException
- Thrown if the system command could not be issued.
-
killProcess
public static void killProcess(java.lang.Process process) throws java.io.IOException
Kills the provided process with a operating system's kill command.- Parameters:
process
- The process to be killed.- Throws:
java.io.IOException
- Thrown if the system command could not be issued.
-
-