Package org.jvnet.winp
Class WinProcess
- java.lang.Object
-
- org.jvnet.winp.WinProcess
-
public class WinProcess extends Object
Represents a Windows process.On Windows, there are several system pseudo-processes, for which many of the getter invocations would fail. This includes "system idle process" (which always seem to have PID=0) and "System" (which always seem to have PID=4)
- Author:
- Kohsuke Kawaguchi
-
-
Constructor Summary
Constructors Constructor Description WinProcess(int pid)
Wraps a process ID.WinProcess(Process proc)
WrapsProcess
intoWinProcess
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Iterable<WinProcess>
all()
Enumerates all the processes in the system.static void
enableDebugPrivilege()
Elevates the security privilege of this process so that we can obtain information about processes owned by other users.String
getCommandLine()
Gets the command line given to this process.TreeMap<String,String>
getEnvironmentVariables()
Gets the environment variables of this process.int
getPid()
Gets the process ID.boolean
isCriticalProcess()
boolean
isRunning()
void
kill()
void
killRecursively()
Kills this process and all the descendant processes that this process launched.boolean
sendCtrlC()
Sends Ctrl+C to the process.void
setPriority(int priority)
Sets the execution priority of this thread.String
toString()
-
-
-
Constructor Detail
-
WinProcess
public WinProcess(int pid)
Wraps a process ID.
-
WinProcess
public WinProcess(Process proc)
WrapsProcess
intoWinProcess
.
-
-
Method Detail
-
getPid
public int getPid()
Gets the process ID.
-
killRecursively
public void killRecursively()
Kills this process and all the descendant processes that this process launched.
-
kill
public void kill()
-
sendCtrlC
@CheckReturnValue public boolean sendCtrlC() throws WinpException
Sends Ctrl+C to the process. Due to the Windows platform specifics, this execution will spawn a separate thread to deliver the signal. This process is expected to be executed within a 5-second timeout.- Returns:
true
if the signal was delivered successfully- Throws:
WinpException
- Execution error
-
isRunning
public boolean isRunning()
-
isCriticalProcess
public boolean isCriticalProcess()
-
setPriority
public void setPriority(int priority)
Sets the execution priority of this thread.- Parameters:
priority
- One of the values fromPriority
.
-
getCommandLine
public String getCommandLine()
Gets the command line given to this process. On Windows, a command line is a single string, unlike Unix. The tokenization semantics is up to applications.- Throws:
WinpException
- If Winp fails to obtain the command line. The process may be dead or there is not enough security privileges.
-
getEnvironmentVariables
public TreeMap<String,String> getEnvironmentVariables()
Gets the environment variables of this process.The returned map has a case-insensitive comparison semantics.
- Returns:
- Never null.
- Throws:
WinpException
- If Winp fails to obtain the environment variables. The process may be dead or there is not enough security privileges.
-
all
public static Iterable<WinProcess> all()
Enumerates all the processes in the system.- Returns:
- Never null.
- Throws:
WinpException
- If the enumeration fails.
-
enableDebugPrivilege
public static void enableDebugPrivilege()
Elevates the security privilege of this process so that we can obtain information about processes owned by other users.Otherwise some of the getter methods may fail with
WinpException
due to access denied error.
-
-