implement Process.destroy

This commit is contained in:
Joshua Warner 2011-11-03 12:30:51 -06:00
parent 76f57fc931
commit 90dc552463
3 changed files with 44 additions and 1 deletions

View File

@ -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 File

@ -122,6 +122,8 @@ public class Runtime {
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 class Runtime {
}
public void destroy() {
throw new RuntimeException("not implemented");
kill(pid);
}
public InputStream getInputStream() {

31
test/Processes.java Normal file
View File

@ -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);
}
}
}