Git Product home page Git Product logo

winp's Introduction

Windows process management library (WinP)

Build status

This project develops a library that lets you control Windows processes better, beyond what's available in JDK.

Features summary:

  • Windows machine management (logoff user, shutdown/restart machine)
  • Thread priority management
  • Process termination (including the recursive termination)
  • Process info acquisition
  • etc.

See the library's Javadoc for more details.

Maven repository

Starting with 1.29, this library is published at:

<repository>
  <id>repo.jenkins-ci.org</id>
  <url>https://repo.jenkins-ci.org/releases/</url>
</repository>

Java support

Starting with 1.29, this library requires Java 11 or newer.

WinP Library includes native libraries for all supported platforms, hence it can run on both 32bit and 64bit Java versions without any additional configuration.

Platform support

The library supports x86 and amd64 architectures. ARM architecture is not supported. Please raise an issue to the library if you need ARM support && ready to provide proper test environment.

โ— It is not recommended to use WinP with 32bit Java on a 64bit operating system. In such case the library will be running in the WoW64 mode; and it will be unable to properly work with 64bit processes in the system. E.g. any process information query call (e.g. Environment variables retrieval) may fail if you run it against 64bit process.

Supported Windows versions

The current version of WinP is known to work correctly on the following Windows versions:

  • Windows XP SP2 and above
  • Windows Server 2003 and above

Other Windows product lines are not being actively tested though WinP may work there.

โ— Minimal required Windows version is a subject to change in next releases of WinP.

License

MIT License

winp's People

Contributors

basil avatar bcastellucci avatar dependabot[bot] avatar gorrus avatar jglick avatar jtnord avatar kohsuke avatar notmyfault avatar oleg-nenashev avatar os97673 avatar pbo-linaro avatar phejl avatar segrey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

winp's Issues

What license is winp under?

I couldn't find the license anywhere... So, it'd be nice if it could be added to the code with a LICENSE.txt (I'd like to use it in PyDev: http://pydev.org, so, it'd be nice it if was an EPL-compatible license).

Make @segrey a co-mailtainer of WinP

Hi @segrey . This is a follow-up to our discussion about the component ownership before the new year. I am ready to proceed with this topic.

Just to provide some context, I still need to re-setup the Windows development environment to do a release with MVS 14.0 tools version. I will likely be able to do it in few weeks when I get a new laptop (migrating from Mac to Windows). I hope to have a bit more time to maintain this component and the release environment, but it will be great to work together on this component.

`mvn clean` does not clean native components

Invoking mvn clean removes the target/ directory but not the native components. It should somehow invoke build.cmd clean in a similar fashion to how the normal build invokes build.cmd build.

[JENKINS-48347] - Failed to locate JAR file by URL zip:

Greetings.

I am getting an exception from winp (v1.25, bundled with Jenkins LTS 2.73.3), specifically from Native.java, line 144.

I believe it is coming from the getJarFile() method. There is an if-statement on line 166 that returns null if the url doesn't start with jar: or wsjar:.

In my case the url starts with zip: so it is failing the test & coming up null.

Does this need a code fix or is there something I can do on my end to workaround the issue?


Dec 01, 2017 3:58:35 PM org.jvnet.winp.Native loadByUrl
WARNING: Failed to load DLL from static location
java.lang.RuntimeException: Failed to locate JAR file by URL zip:C:/[[[path redacted]]]/servers/AdminServer/tmp/_WL_user/Jenkins_LTS_2.73.3/frocxk/war/WEB-INF/lib/winp-1.25.jar!/winp.x64.dll
at org.jvnet.winp.Native.extractToStaticLocation(Native.java:144)
at org.jvnet.winp.Native.loadByUrl(Native.java:129)
at org.jvnet.winp.Native.load(Native.java:99)
at org.jvnet.winp.Native.(Native.java:70)
at org.jvnet.winp.WinProcess.enableDebugPrivilege(WinProcess.java:226)
at hudson.util.ProcessTree$Windows.(ProcessTree.java:555)
at hudson.util.ProcessTree.get(ProcessTree.java:350)
at hudson.Launcher$LocalLauncher.kill(Launcher.java:949)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:502)
at hudson.model.Run.execute(Run.java:1737)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:421)

Enable CD

Now that #116 has landed, the next step is to enable JEP-229 CD for this repository, using GitHub Actions (as is standard for CD in the Jenkins project). The CD work should largely follow https://www.jenkins.io/doc/developer/publishing/releasing-cd/ but may be slightly more involved in that it needs to run on a Windows 2019 system in GitHub Actions rather than a Linux system in GitHub Actions (as the instructions currently describe).

The standard process used in Jenkins is to run CD after CI has passed, skipping the tests in CD. Since this CD build is more complicated, and since the test suite runs in milliseconds, it may be desirable to also run the tests again during CD.

One complication is that CD needs to sign the binaries after building them but before putting them in the JAR. The signing should take place as described here with some commands like:

WinSDK/bin/signtool sign /f path-to-certificate.pfx /p PASSWORD /t http://timestamp.digicert.com native\x64\Release\winp.dll
WinSDK/bin/signtool sign /f path-to-certificate.pfx /p PASSWORD /t http://timestamp.digicert.com native\x64\Release\winp.x64.dll

It may be necessary to engage with the Jenkins infrastructure team for access to a certificate. The password for the certificate can be stored by a GitHub administrator as a secret in the "Actions secrets and variables" configuration for this repository, where it may be consumed by the CD (but not CI!) build.

org.jvnet.winp.WinpException: Failed to read environment variable - [JENKINS-30782]

According to the code, the getCmdLineAndEnvVars() command is unreliable on newer modern OS versions.

The last ReadProcessMemory command may fail:

	// Checking the read size is more likely to result in success than checking the BOOL that is
	// returned by ReadProcessMemory, on newer versions of Windows. That said, neither approach
	// is particularly reliable past Vista. This approach differs from checking the BOOL in that
	// it will succeed for partial reads that read _some_ data, where the other approach fails.

There are many usages of the command in WinP itself and in the dependent codebase like Jenkins ( JENKINS-30782). Example of the log in Jenkins:

The error that I get is ERROR: Build step failed with exception
org.jvnet.winp.WinpException: Failed to read environment variable table error=299 at .\envvar-cmdline.cpp:201
at org.jvnet.winp.Native.getCmdLineAndEnvVars(Native Method)
at org.jvnet.winp.WinProcess.parseCmdLineAndEnvVars(WinProcess.java:126)
at org.jvnet.winp.WinProcess.getCommandLine(WinProcess.java:102)
at org.jvnet.winp.WinProcess.killRecursively(WinProcess.java:66)
at hudson.util.ProcessTree$Windows$1.killRecursively(ProcessTree.java:425)
at hudson.util.ProcessTree.killAll(ProcessTree.java:141)
at hudson.Proc$LocalProc.destroy(Proc.java:379)
at hudson.Proc$LocalProc.join(Proc.java:352)
at hudson.Launcher$ProcStarter.join(Launcher.java:389)
at hudson.tasks.Ant.perform(Ant.java:217)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.Build$BuildExecution.build(Build.java:205)
at hudson.model.Build$BuildExecution.doRun(Build.java:162)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
at hudson.model.Run.execute(Run.java:1741)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:408

Proposals:

  • Fix the failing ReadProcessMemory operation if possible
  • Reduce the scope of the EnvVars usage, provide API for retrieving the CMD Line only
  • It won't help Jenkins, which terminates processes by using EnvVars filters (e.g. by BUILD_NUMBER env. var)

Proposal: Change release order

According to the winp-1.23 release experience, it makes sense to push changes to GitHub only when the release process uploads the package to Sonatype Staging Area and pushes the documentation to the gh-pages branch

Windows Defender detects a virus in winp-1.23

Windows 8.1 Pro 64-bit

Windows Defender | About

Antimalware Client Version: 4.7.205.0
Engine Version: 1.1.11701.0
Antivirus definition: 1.199.2816.0
Antispyware definition: 1.199.2816.0
Network Inspection System Engine Version: 2.1.11502.0
Network Inspection System Definition Version: 114.3.0.0

http://windows.microsoft.com/en-us/windows/using-defender#1TC=windows-8

Downloading https://github.com/kohsuke/winp/archive/winp-1.23.zip using Chrome 43.0.2357.124 results in

winp-winp-1.23.zip Anti-virus software detected a virus.
https://codeload.github.com/kohsuke/winp/zip/winp-1.23

gh-pages: Missing persmissions in GitHub repo (release fails)

Seems several GitHub permissions are missing on my account.

  • mvn:release step was able to create an empty version (seems to be OK)
  • the tag has been also added => commit & push operations work well
  • winp-1.23 snapshot is also available on Maven Central
  • I was able to commit to gh-pages directly ( db20e0c )
  • Seems https://github.com/kohsuke/wagon-gitsite somehow takes a wrong Git installation or ignores GIT_SSH variable
[INFO] [INFO] --- maven-site-plugin:3.3:deploy (default-deploy) @ winp ---
[INFO] [INFO] Parent project loaded from repository: org.kohsuke:pom:pom:10
[INFO] scm:git:ssh://github.com/kohsuke/winp.git/ - Session: Opened
[INFO] [INFO] Pushing /remote/ru20home1/nenashev/Documents/jenkins/libs/winp/target/checkout/target/site
[INFO] [INFO]    >>> to scm:git:ssh://github.com/kohsuke/winp.git/./
[INFO] Uploading: ./ to scm:git:ssh://github.com/kohsuke/winp.git/
[INFO]
[INFO] [INFO] Executing: /bin/sh -c cd /remote/ru20home1/nenashev/Documents/jenkins/libs/winp/target/checkout/. && git ls-files
[INFO] [INFO] Working directory: /remote/ru20home1/nenashev/Documents/jenkins/libs/winp/target/checkout/.
[INFO] [INFO] Executing: /bin/sh -c cd /tmp/wagon-scm324908943.checkout && git init
[INFO] [INFO] Working directory: /tmp/wagon-scm324908943.checkout
[INFO] [INFO] Executing: /bin/sh -c cd /tmp/wagon-scm324908943.checkout && git remote add origin ssh://github.com/kohsuke/winp.git
[INFO] [INFO] Working directory: /tmp/wagon-scm324908943.checkout
[INFO] [INFO] Executing: /bin/sh -c cd /tmp/wagon-scm324908943.checkout && git pull origin refs/heads/gh-pages
[INFO] [INFO] Working directory: /tmp/wagon-scm324908943.checkout
[INFO]  Transfer error: org.apache.maven.scm.ScmException: Unable to commit file. The git-pull command failed. Permission denied (publickey).
[INFO] fatal: The remote end hung up unexpectedly
[INFO]
[INFO] scm:git:ssh://github.com/kohsuke/winp.git/ - Session: Disconnecting
[INFO] scm:git:ssh://github.com/kohsuke/winp.git/ - Session: Disconnected
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD FAILURE
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 55.243 s
[INFO] [INFO] Finished at: 2015-02-17T08:45:39+03:00
[INFO] [INFO] Final Memory: 39M/367M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-site-plugin:3.3:deploy (default-deploy) on project winp: Error uploading site: Error checking out: Unable to commit file. The git-pull command failed. Permission denied (publickey).
[INFO] [ERROR] fatal: The remote end hung up unexpectedly
[INFO] [ERROR] -> [Help 1]
[INFO] [ERROR]
[INFO] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[INFO] [ERROR] Re-run Maven using the -X switch to enable full debug logging.
[INFO] [ERROR]
[INFO] [ERROR] For more information about the errors and possible solutions, please read the following articles:
[INFO] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:08 min
[INFO] Finished at: 2015-02-17T08:45:40+03:00
[INFO] Final Memory: 11M/233M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.3.2:perform (default-cli) on project winp: Maven execution failed, exit code: '1' -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Flickering console window when sending Ctrl+C

When a process is started without console window, executing org.jvnet.winp.WinProcess#sendCtrlC leads to running sendctrlc.exe with a new console visible window. Even though sendctrlc.exe is a short-living process, the console window flickering is noticeable.

To reproduce the issue, please see myapp.zip.
It's a simple Java Swing application running new WinProcess(123).sendCtrlC() on button click.

  1. Unzip the project and optionally rebuild it.
  2. Run the app with run.cmd. Or start it manually, just ensure you're using javaw.exe instead of java.exe to start the process without console window.
  3. A window with a single button will appear:
    image
  4. Click it and a console window will appear and hide.

Get rid of binaries in the repo

The build.cmd flow for WinP on Windows does not require pushing binaries to GitHub though it may be required if @kohsuke needs non-Windows machine to spin releases. The approach needs to be investigated.

In the latter case maybe it is possible to stage native binaries in AppVeyor/NuGet and then just download them for the release purpose. Not good since it requires untested rebuild of the WinP JAR

[JENKINS-20289] - Add support of child processes retrieval

Jenkins background:

The current Jenkins version uses "winp" to recursively terminate Windows processes. Such approach works well, but ProcessKiller extensions cannot be invoked for the entire process tree on Windows, so their behavior differs from Linux.

I propose to replace getChildren() and getParent() method stubs by working implementations using additional methods in the native part.

My use-case:

https://issues.jenkins-ci.org/browse/JENKINS-20289

UNC paths are not supported

Hello,

If winp.jar is located in unc path (with write access) the following exception can occur :

16 2011 15:26:49 org.jvnet.winp.Native load
WARNING: Failed to write winp.dll
java.io.FileNotFoundException: \Optimus\TestWinp1.16\lib\winp.dll (Cannot find the file specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.(Unknown Source)
at java.io.FileOutputStream.(Unknown Source)
at org.jvnet.winp.Native.load(Native.java:81)
at org.jvnet.winp.Native.(Native.java:52)
at org.jvnet.winp.WinProcess.(WinProcess.java:41)
at Test.main(Test.java:112)
Exception in thread "main" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: \Optimus\TestWinp1.16\lib\winp.dll
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at org.jvnet.winp.Native.loadDll(Native.java:158)
at org.jvnet.winp.Native.load(Native.java:90)
at org.jvnet.winp.Native.(Native.java:52)
at org.jvnet.winp.WinProcess.(WinProcess.java:41)
at Test.main(Test.java:112)

Changes to fix it, in org/jvnet/winp/Native.java (form winp1.5)

64,65c64,65
was:

if(filePortion.startsWith("/"))
filePortion = "/"+filePortion;

should be:
if(filePortion.startsWith("//"))
filePortion = filePortion.substring(2);

69c69
was:
if(!dllFile.exists()/* || jarFile.lastModified()>dllFile.lastModified()*/) {

should be:
if(!dllFile.exists() || jarFile.lastModified()>dllFile.lastModified()) {

Thank you

winp sometimes kills random processes when using killRecursive

The way that winp's killRecursive works means that occasionally, the tree it tries to walk hits an old process whose parent exited before them, but had the same process id as one of the processes in the tree we are trying to kill (The PPID of these children is not cleared or reset when the parent exits).

This means that random processes die and on a windows VM, it can BSOD the entire VM.

support arm platform

Face with the problem where DLL winp.x64 cannot load on ARM machine
Tried using OpenJDK 17.0.0, OpenJDK 16.0.2 on tosh have error:
WARNING: Failed to load DLL from static location
java.lang.UnsatisfiedLinkError: C:\jenkins\remoting\jarCache\44\winp.x64.BFFE30B3B50581290B1866EF8D48C609.dll: Can't load AMD 64-bit .dll on a ARM 64-bit platform

winp.killRecursively() EXCEPTION_STACK_OVERFLOW

# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_STACK_OVERFLOW (0xc00000fd) at pc=0x7749df0f, pid=13492, tid=13832
#
# JRE version: Java(TM) SE Runtime Environment (7.0_67-b01) (build 1.7.0_67-b01)
# Java VM: Java HotSpot(TM) Client VM (24.65-b04 mixed mode, sharing windows-x86 )
# Problematic frame:
# C  [ntdll.dll+0x2df0f]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
Stack: [0x06670000,0x066c0000],  sp=0x06671000,  free space=4k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [ntdll.dll+0x2df0f]
C  [ntdll.dll+0x2e0f2]
C  [KERNELBASE.dll+0x158de]

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.jvnet.winp.Native.kill(IZ)Z+0
j  org.jvnet.winp.WinProcess.killRecursively()V+49
j  com.ctrip.cap.lanucher.WinAppiumServer.stopAppium()V+30
j  com.ctrip.cap.AppiumContext.closeQuietly()V+45
j  com.ctrip.cap.appium.AppiumTest.destroyDriver(Lorg/testng/ITestContext;Lorg/testng/ITestResult;Ljava/lang/reflect/Method;)V+132
v  ~StubRoutines::call_stub
J 2108  sun.reflect.NativeMethodAccessorImpl.invoke0(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (0 bytes) @ 0x02ae0d9d [0x02ae0d20+0x7d]
J 2107 C1 sun.reflect.NativeMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (91 bytes) @ 0x02ae1210 [0x02ae1010+0x200]
J 1204 C1 sun.reflect.DelegatingMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (10 bytes) @ 0x02809f40 [0x02809f10+0x30]
J 1234 C1 java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (63 bytes) @ 0x0297b47c [0x0297b3c0+0xbc]
j  org.testng.internal.MethodInvocationHelper.invokeMethod(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+235
j  org.testng.internal.Invoker.invokeConfigurationMethod(Ljava/lang/Object;Lorg/testng/ITestNGMethod;[Ljava/lang/Object;ZZLorg/testng/ITestResult;)V+132
j  org.testng.internal.Invoker.invokeConfigurations(Lorg/testng/IClass;Lorg/testng/ITestNGMethod;[Lorg/testng/ITestNGMethod;Lorg/testng/xml/XmlSuite;Ljava/util/Map;[Ljava/lang/Object;Ljava/lang/Object;Lorg/testng/ITestResult;)V+318
j  org.testng.internal.Invoker.invokeMethod(Ljava/lang/Object;Lorg/testng/ITestNGMethod;[Ljava/lang/Object;ILorg/testng/xml/XmlSuite;Ljava/util/Map;Lorg/testng/ITestClass;[Lorg/testng/ITestNGMethod;[Lorg/testng/ITestNGMethod;Lorg/testng/internal/ConfigurationGroupMethods;Lorg/testng/internal/Invoker$FailureContext;)Lorg/testng/ITestResult;+565
j  org.testng.internal.Invoker.invokeTestMethod(Ljava/lang/Object;Lorg/testng/ITestNGMethod;[Ljava/lang/Object;ILorg/testng/xml/XmlSuite;Ljava/util/Map;Lorg/testng/ITestClass;[Lorg/testng/ITestNGMethod;[Lorg/testng/ITestNGMethod;Lorg/testng/internal/ConfigurationGroupMethods;Lorg/testng/internal/Invoker$FailureContext;)Lorg/testng/ITestResult;+29
j  org.testng.internal.Invoker.invokeTestMethods(Lorg/testng/ITestNGMethod;Lorg/testng/xml/XmlSuite;Ljava/util/Map;Lorg/testng/internal/ConfigurationGroupMethods;Ljava/lang/Object;Lorg/testng/ITestContext;)Ljava/util/List;+664
j  org.testng.internal.TestMethodWorker.invokeTestMethods(Lorg/testng/ITestNGMethod;Ljava/lang/Object;Lorg/testng/ITestContext;)V+19
j  org.testng.internal.TestMethodWorker.run()V+60
j  java.util.concurrent.ThreadPoolExecutor.runWorker(Ljava/util/concurrent/ThreadPoolExecutor$Worker;)V+95
j  java.util.concurrent.ThreadPoolExecutor$Worker.run()V+5
j  java.lang.Thread.run()V+11
v  ~StubRoutines::call_stub

Failure to merge: winp sometimes kills random processes when using killRecursive

The following issue describes a problem still present in winp due to a failure to merge the pull request correctly: winp sometimes kills random processes when using killRecursive

Specifically this pull request was not correctly merged: #8

A simple check would seem to indicate the commit was merged:

$ git tag --contains 27a1f7ca64f4dfa0f243dfc834e671ffc3c0b8b9
1.23-beta
winp-1.17
winp-1.18
winp-1.19
winp-1.20
winp-1.21
winp-1.22
winp-1.23

However the merge (b859526) actually reverted the change during the merge. Note that native/winp.cpp is listed as a conflict. It would appear a merge strategy "ours" was used to resolve the conflict, hence discarding the change.

We encountered this problem only recently because we have been using the 1.17-atlassian1 release of winp (found here https://github.com/bturner/winp/tree/winp-1.17-atlassian1), which does include a fix for the issue, for a long time. We recently upgraded to the 1.19 release from the primary winp repository and have been seeing this problem since.

[JENKINS-48785] getCmdLineAndEnvVars is not compatible with 32bit windows os

The getCmdLineAndEnvVars function seems to be incompatible with 32bit windows os.

We currently have a jenkins server that runs on a x64 windows machine.
This machine starts a java process on a jenkins slave that is running on a 32bit windows machine.

The process on the 32bit machine cannot be killed. The getCmdLineAndEnvVars checks if the process is wow64, which it is not according to the msdn documentation:

A pointer to a value that is set to TRUE if the process is running under WOW64. If the process is running under 32-bit Windows, the value is set to FALSE. If the process is a 64-bit application running under 64-bit Windows, the value is also set to FALSE.

This means the iswow64 check will always fail, causing an error. This also means the process will never get cleaned.

The check should also look for PROCESSOR_ARCHITECTURE_INTEL and not just wow64

Provide more detailed error when class org.jvnet.winp.Native could not be initialized

Sometimes return new WinProcess(myProcess).sendCtrlC(); fails with with the following exception:

java.lang.NoClassDefFoundError: Could not initialize class org.jvnet.winp.Native
	at org.jvnet.winp.WinProcess.<init>(WinProcess.java:46)
	at com.intellij.execution.process.KillableProcessHandler.destroyProcessGracefully(KillableProcessHandler.java:168)
	at com.intellij.execution.process.KillableProcessHandler.doDestroyProcess(KillableProcessHandler.java:143)
	at com.intellij.execution.process.KillableProcessHandler.destroyProcessImpl(KillableProcessHandler.java:127)
	at com.intellij.execution.process.ProcessHandler$1.run(ProcessHandler.java:100)
	at com.intellij.execution.process.ProcessHandler$TasksRunner.execute(ProcessHandler.java:256)
	at com.intellij.execution.process.ProcessHandler.destroyProcess(ProcessHandler.java:95)
	at com.intellij.execution.ui.RunContentManagerImpl$CloseListener.closeQuery(RunContentManagerImpl.java:696)
	at com.intellij.execution.ui.RunContentManagerImpl$CloseListener.contentRemoveQuery(RunContentManagerImpl.java:649)
	at com.intellij.ui.content.impl.ContentManagerImpl.fireContentRemoveQuery(ContentManagerImpl.java:561)
	at com.intellij.ui.content.impl.ContentManagerImpl.removeContent(ContentManagerImpl.java:201)
	at com.intellij.ui.content.impl.ContentManagerImpl.removeContent(ContentManagerImpl.java:166)
	at com.intellij.openapi.wm.impl.content.ContentTabLabel$1.lambda$getAction$0(ContentTabLabel.java:69)
	at com.intellij.openapi.wm.impl.content.ContentTabLabel$2.execute(ContentTabLabel.java:134)
	at com.intellij.util.ui.BaseButtonBehavior$MyMouseListener.execute(BaseButtonBehavior.java:173)
	at com.intellij.util.ui.BaseButtonBehavior$MyMouseListener.mouseReleased(BaseButtonBehavior.java:156)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
	at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:289)
	at java.awt.Component.processMouseEvent(Component.java:6548)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3325)
	at java.awt.Component.processEvent(Component.java:6313)
	at java.awt.Container.processEvent(Container.java:2237)
	at java.awt.Component.dispatchEventImpl(Component.java:4903)
	at java.awt.Container.dispatchEventImpl(Container.java:2295)
	at java.awt.Component.dispatchEvent(Component.java:4725)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4889)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4526)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4467)
	at java.awt.Container.dispatchEventImpl(Container.java:2281)
	at java.awt.Window.dispatchEventImpl(Window.java:2746)
	at java.awt.Component.dispatchEvent(Component.java:4725)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:764)
	at java.awt.EventQueue.access$500(EventQueue.java:98)
	at java.awt.EventQueue$3.run(EventQueue.java:715)
	at java.awt.EventQueue$3.run(EventQueue.java:709)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
	at java.awt.EventQueue$4.run(EventQueue.java:737)
	at java.awt.EventQueue$4.run(EventQueue.java:735)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:734)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:718)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:663)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:366)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

The exception was received automatically from a WebStorm instance. It's also known that OS is Windows 10.
Unfortunately, there is no "caused by" linked exception making it impossible to figure out the cause.
Is it possible to enhance thrown exception?

Exception while getting commandline

Hi,

I'm trying to get the commandline of a WinProcess constructed via pid and got following exception:

org.jvnet.winp.WinpException: Failed to read environment variable table error=299 at .\envvar-cmdline.cpp:114
at org.jvnet.winp.Native.getCmdLineAndEnvVars(Native Method)
at org.jvnet.winp.WinProcess.parseCmdLineAndEnvVars(WinProcess.java:114)
at org.jvnet.winp.WinProcess.getCommandLine(WinProcess.java:90)
at de.heuboe.csb.manage.uz.stdImpl.StdUZSystemMonitor.restart(StdUZSystemMonitor.java:297)
at de.heuboe.csb.manage.uz.stdImpl.StdUZManagerImpl.init(StdUZManagerImpl.java:84)
at de.heuboe.csb.manage.uz.stdImpl.StdUZFactory.init(StdUZFactory.java:33)
at de.heuboe.csb.manage.uz.stdImpl.StdUZFactory.(StdUZFactory.java:26)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:105)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:278)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:993)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:897)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:574)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93)
at de.heuboe.csb.manage.manager.CorbaServiceTestRunner.main(CorbaServiceTestRunner.java:19)

System is: Windows 7/x64 Professional.

Thx

Milraun

Send Ctrl+C does not work on Windows 8.1

Windows 8.1 Pro

When running manually:
image

When running via Java API:

Exception in thread "main" org.jvnet.winp.WinpException: External Ctrl+C execution failed for process pid=1160. Ctrl+C process exited with code -1073741515: Failed to attach to the console (see the AttachConsole WinAPI call). error=0 at winp.cpp:59
	at org.jvnet.winp.Native.sendCtrlC(Native Method)
	at org.jvnet.winp.Native.sendCtrlC(Native.java:90)
	at org.jvnet.winp.WinProcess.sendCtrlC(WinProcess.java:93)
	at example.Main.main(Main.java:29)

See example project to reproduce: stop-child-process.zip.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.