本文整理汇总了Java中org.jvnet.winp.WinProcess类的典型用法代码示例。如果您正苦于以下问题:Java WinProcess类的具体用法?Java WinProcess怎么用?Java WinProcess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WinProcess类属于org.jvnet.winp包,在下文中一共展示了WinProcess类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: killProcessTree
import org.jvnet.winp.WinProcess; //导入依赖的package包/类
@Override
public boolean killProcessTree(@NotNull Process process) {
if (SystemInfo.isWindows) {
try {
WinProcess winProcess = createWinProcess(process);
winProcess.killRecursively();
return true;
}
catch (Throwable e) {
LOG.info("Cannot kill process tree", e);
}
}
else if (SystemInfo.isUnix) {
return UnixProcessManager.sendSigKillToProcessTree(process);
}
return false;
}
示例2: stop
import org.jvnet.winp.WinProcess; //导入依赖的package包/类
public synchronized void stop() {
// make sure we are in the correct state
if (getStatus() != Status.RUNNING &&
getStatus() != Status.STARTING_UP)
{
throw new IllegalStateException("Can't stop runner in " +
getStatus() + " state");
}
setStatus(Status.SHUTTING_DOWN);
// workaround for Windows issue when stopping a process. Use
// an external library that does a better job stopping
// processes than Process.destroy()
if (System.getProperty("os.name").startsWith("Windows")) {
WinProcess wp = new WinProcess(proc);
wp.killRecursively();
} else {
proc.destroy();
}
}
示例3: killProcessTree
import org.jvnet.winp.WinProcess; //导入依赖的package包/类
@Override
public boolean killProcessTree(@NotNull Process process) {
if (SystemInfo.isWindows) {
try {
new WinProcess(process).killRecursively();
return true;
}
catch (Throwable e) {
LOG.info("Cannot kill process tree");
LOG.info(e);
}
}
else if (SystemInfo.isUnix) {
return UnixProcessManager.sendSigKillToProcessTree(process);
}
return false;
}
示例4: killProcessTree
import org.jvnet.winp.WinProcess; //导入依赖的package包/类
@Override
public boolean killProcessTree(@Nonnull Process process) {
if (SystemInfo.isWindows) {
try {
WinProcess winProcess = createWinProcess(process);
winProcess.killRecursively();
return true;
}
catch (Throwable e) {
LOG.info("Cannot kill process tree", e);
}
}
else if (SystemInfo.isUnix) {
return UnixProcessManager.sendSigKillToProcessTree(process);
}
return false;
}
示例5: killProcessAndItsChildren
import org.jvnet.winp.WinProcess; //导入依赖的package包/类
/**
* Kill started process and makes best effort to kill its children processes.<br />
* Warning is logged if issues is detected.<br />
* Note that this might be invoked after some time if not sure that all child processes are already started.
*/
public void killProcessAndItsChildren() {
if (OperatingSystemType.getCurrentOsType().isUnix()) {
// first kill child processes because otherwise their parent ID is changed to 1
int pid = getProcessId();
String command = "pkill -P " + pid;
if (log.isDebugEnabled()) {
log.debug("Try to destroy child processes with '" + command + "'");
}
int exitCode = -1;
try {
exitCode = Runtime.getRuntime().exec(command).waitFor();
} catch (Exception e) {
throw new ProcessExecutorException("Could not kill the process with id '" + pid + "'", e);
}
killProcess(); // kill this process
if (exitCode != 0) {
log.warn("Error while trying to kill subprocesses. Exit code returned from '" + command
+ "' command: " + exitCode);
}
} else if (OperatingSystemType.getCurrentOsType().isWindows()) { // Windows assumed
// use org.jvnet.winp.WinProcess
log.debug("Windows detected and will try to kill whole subtree.");
new WinProcess(theProcess).killRecursively();
} else {
throw new IllegalStateException("Not supported operating system type. Report the case to ATS team");
}
}
示例6: setProcess
import org.jvnet.winp.WinProcess; //导入依赖的package包/类
@Override
void setProcess(CdpProcess process) {
WinProcess winProcess = new WinProcess(process.getProcess());
pid = winProcess.getPid();
cdp4jId = winProcess.getEnvironmentVariables().get("CDP4J_ID");
}
示例7: convertToWinProcess
import org.jvnet.winp.WinProcess; //导入依赖的package包/类
@NotNull
private WinProcess convertToWinProcess(@NotNull final Process process) {
// copied from com.intellij.execution.process.impl.OSProcessManagerImpl#createWinProcess
if (process instanceof RunnerWinProcess) {
return new WinProcess(((RunnerWinProcess)process).getOriginalProcess());
}
else {
return new WinProcess(process);
}
}
示例8: main
import org.jvnet.winp.WinProcess; //导入依赖的package包/类
public static void main(String[] args) {
if (args.length != 1) {
System.out.println("You have to give a regular expression in parameter (ex: .*proactive.*)");
System.exit(1);
}
final String regex = args[0];
Iterable<WinProcess> allProcess = WinProcess.all();
for (WinProcess process : allProcess) {
try {
String commandLine = process.getCommandLine();
// System.out.println("COMMAND LINE: " + commandLine);
if (commandLine.matches(".*" + WindowsCleaner.class.getName() + ".*")) {
// System.out.println(process.getPid() + " is a Windows Cleaner");
} else {
if (commandLine.matches(regex)) {
// System.out.println(process.getPid() + " matches " + regex);
process.killRecursively();
System.out.println("Killed " + process.getPid() + " " + commandLine);
} else {
// System.out.println(process.getPid() + " do not match " + regex);
}
}
} catch (WinpException e) {
// Miam Miam Miam
}
}
}
示例9: createWinProcess
import org.jvnet.winp.WinProcess; //导入依赖的package包/类
@Nonnull
private static WinProcess createWinProcess(@Nonnull Process process) {
if (process instanceof RunnerWinProcess) {
RunnerWinProcess runnerWinProcess = (RunnerWinProcess) process;
return new WinProcess(runnerWinProcess.getOriginalProcess());
}
return new WinProcess(process);
}
示例10: createWinProcess
import org.jvnet.winp.WinProcess; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@NotNull
private static WinProcess createWinProcess(@NotNull Process process) {
if (process instanceof RunnerWinProcess) process = ((RunnerWinProcess)process).getOriginalProcess();
return new WinProcess(process);
}
示例11: Windows
import org.jvnet.winp.WinProcess; //导入依赖的package包/类
Windows() {
for (final WinProcess p : WinProcess.all()) {
int pid = p.getPid();
if (pid == 0 || pid == 4)
continue; // skip the System Idle and System processes
super.processes.put(pid, new OSProcess(pid) {
private EnvVars env;
private List<String> args;
public OSProcess getParent() {
// windows process doesn't have parent/child relationship
return null;
}
public void killRecursively() throws InterruptedException {
LOGGER.finer("Killing recursively " + getPid());
p.killRecursively();
}
public void kill() throws InterruptedException {
LOGGER.finer("Killing " + getPid());
p.kill();
}
@Override
public synchronized List<String> getArguments() {
if (args == null)
args = Arrays.asList(QuotedStringTokenizer.tokenize(p.getCommandLine()));
return args;
}
@Override
public synchronized EnvVars getEnvironmentVariables() {
if (env != null)
return env;
env = new EnvVars();
try {
env.putAll(p.getEnvironmentVariables());
} catch (WinpException e) {
LOGGER.log(FINE, "Failed to get environment variable ", e);
}
return env;
}
});
}
}
示例12: get
import org.jvnet.winp.WinProcess; //导入依赖的package包/类
@Override
public OSProcess get(Process proc) {
return get(new WinProcess(proc).getPid());
}