Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jnr.posix.POSIX.kill(long pid, int signal) fails on Windows #159

Open
fgretief opened this issue Jan 13, 2021 · 2 comments
Open

jnr.posix.POSIX.kill(long pid, int signal) fails on Windows #159

fgretief opened this issue Jan 13, 2021 · 2 comments

Comments

@fgretief
Copy link

We get the exception below when pressing CTRL-C when running the application via Maven that uses a custom Maven plugin. The plug-in uses the jnr.posix.POSIX.kill() function to terminate the running program. But the kill is not implemented for Windows in jnr-posix. Because of this we have to open Process Explorer and manually kill the java process that is left running in the background. The first 50 times this was ok, but it is getting very tiresome.

What will it take to implement the kill method for Windows in jnr.posix?

Exception in thread "Thread-1" java.lang.IllegalStateException: kill is not implemented in jnr-posix
        at jnr.posix.util.DefaultPOSIXHandler.unimplementedError(DefaultPOSIXHandler.java:28)
        at jnr.posix.WindowsPOSIX.kill(WindowsPOSIX.java:162)
        at org.yamcs.maven.JavaProcessBuilder.lambda$start$0(JavaProcessBuilder.java:61)
        at java.base/java.lang.Thread.run(Thread.java:834)

For reference: https://github.com/yamcs/yamcs-maven-plugin/blob/2c4d4db96aeeefecd45aa2ba5e5bb646f307a67c/src/main/java/org/yamcs/maven/JavaProcessBuilder.java#L61

@headius
Copy link
Member

headius commented Jan 13, 2021

The problem here is that the C kill function does not exist on Windows, so implementing it in jnr-posix would mean emulating POSIX kill behavior on top of equivalent Win32 functions. We have done that in some limited cases when the Windows behavior is easy to match to the POSIX behavior, but I do not know the appropriate calls to make here.

This SO answer might be a clue: https://stackoverflow.com/a/1916668

Since we have the pid in hand, it may be simple to just add these Win32 functions to the ones we already have bound here: https://github.com/jnr/jnr-posix/blob/40fa74d5a4a70cb1dc0773740639f33e57e8c010/src/main/java/jnr/posix/WindowsLibC.java

Then call them from the WindowsPOSIX implementation of kill.

Note this example is only for terminating the process, so we probably should only use this code for SIGKILL and still raise an error for others (until we have a way to send them).

Wanna take a shot at a PR?

@headius
Copy link
Member

headius commented Jan 13, 2021

Another SO post seems to indicate that KILL is the only one for which we have a clear equivalent on Win32:

https://stackoverflow.com/questions/140111/sending-an-arbitrary-signal-in-windows

So I think we could add jnr-posix kill(pid, KILL) support but not much else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants