Package org.jvnet.winp
Class WinProcess
java.lang.Object
org.jvnet.winp.WinProcess
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
ConstructorsConstructorDescriptionWinProcess
(int pid) Wraps a process ID.WinProcess
(Process proc) WrapsProcess
intoWinProcess
. -
Method Summary
Modifier and TypeMethodDescriptionstatic Iterable<WinProcess>
all()
Enumerates all the processes in the system.static void
Elevates the security privilege of this process so that we can obtain information about processes owned by other users.Gets the command line given to this process.Gets the environment variables of this process.int
getPid()
Gets the process ID.boolean
boolean
void
kill()
void
Kills this process and all the descendant processes that this process launched.boolean
Sends Ctrl+C to the process.void
setPriority
(int priority) Sets the execution priority of this thread.toString()
-
Constructor Details
-
WinProcess
public WinProcess(int pid) Wraps a process ID. -
WinProcess
WrapsProcess
intoWinProcess
.
-
-
Method Details
-
toString
-
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
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
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
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
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.
-