Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

implement Process.destroy

  • Loading branch information...
commit 90dc5524635ba0775d5f43229cea90202924c2f2 1 parent 76f57fc
@joshuawarner32 joshuawarner32 authored
View
10 classpath/java-lang.cpp
@@ -279,6 +279,11 @@ Java_java_lang_Runtime_waitFor(JNIEnv* e, jclass, jlong pid, jlong tid)
return exitCode;
}
+extern "C" JNIEXPORT void JNICALL
+Java_java_lang_Runtime_kill(JNIEnv*, jclass, jlong pid) {
+ TerminateProcess(reinterpret_cast<HANDLE>(pid), 1);
+}
+
Locale getLocale() {
const char* lang = "";
const char* reg = "";
@@ -466,6 +471,11 @@ Java_java_lang_Runtime_waitFor(JNIEnv*, jclass, jlong pid, jlong)
return exitCode;
}
+extern "C" JNIEXPORT void JNICALL
+Java_java_lang_Runtime_kill(JNIEnv*, jclass, jlong pid) {
+ kill((pid_t)pid, SIGTERM);
+}
+
Locale getLocale() {
Locale fallback;
View
4 classpath/java/lang/Runtime.java
@@ -122,6 +122,8 @@ private static native void exec(String[] command, long[] process)
private static native void load(String name, boolean mapName);
+ private static native void kill(long pid);
+
public native void gc();
public native void exit(int code);
@@ -147,7 +149,7 @@ public MyProcess(long pid, long tid, int in, int out, int err) {
}
public void destroy() {
- throw new RuntimeException("not implemented");
+ kill(pid);
}
public InputStream getInputStream() {
View
31 test/Processes.java
@@ -0,0 +1,31 @@
+import java.io.IOException;
+
+public class Processes {
+ public static void main(String[] args) {
+ long start = System.currentTimeMillis();
+ try {
+ final Process p = Runtime.getRuntime().exec("sleep 10");
+ new Thread() {
+ public void run() {
+ try {
+ Thread.sleep(100);
+ } catch(InterruptedException e) {
+ // ignore
+ }
+ p.destroy();
+ }
+ }.start();
+ try {
+ p.waitFor();
+ } catch(InterruptedException e) {
+ // ignore
+ }
+ long stop = System.currentTimeMillis();
+ if(stop - start > 5000) {
+ throw new RuntimeException("test failed; we didn't kill the process...");
+ }
+ } catch(IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.