You can implement it in some programming language with can crate native machine (CPU) code. For example C, C++, Fortran, Pascal, D, Go, or assembly. Java compiler - javac produces a universal byte code i.e. an intermediate representation. When java - virtual machine i.e. an interpreter - convert it to the native CPU code first. So that gives you an ability to run some generic program on different CPU architectures or operating systems, without any modification. This paradigm called - write once, run everywhere. However sometimes your program need some functionality implemented in another programming language, or there is some performance critical functionality which should be boost. In this case java virtual machine have an ability to run some external native function. This function must satisfy specific binary interface. I.e. calling convention and naming convention. This function should be put into platform specific shared library i.e. DLL on windows, so on Linux and most of another unix-like systems except Mac OS X - where it is dynalib.
If you really need to use JNI please follow the manual JNI
In any case - in my understanding you are looking for implementation of Process.destroyForcibly
It is platform depended an you can found it in OpenJDK public repository libjava
For example Unix version looks like following:
/*
* Class: java_lang_ProcessHandleImpl
* Method: destroy0
* Signature: (JJZ)Z
*/
JNIEXPORT jboolean JNICALL
Java_java_lang_ProcessHandleImpl_destroy0(JNIEnv *env,
jobject obj,
jlong jpid,
jlong startTime,
jboolean force) {
pid_t pid = (pid_t) jpid;
int sig = (force == JNI_TRUE) ? SIGKILL : SIGTERM;
jlong start = Java_java_lang_ProcessHandleImpl_isAlive0(env, obj, jpid);
if (start == startTime || start == 0 || startTime == 0) {
return (kill(pid, sig) < 0) ? JNI_FALSE : JNI_TRUE;
} else {
return JNI_FALSE;
}
}
You can found it at ProcessHandleImpl_unix
Windows version looks like:
/*
* Destroy the process.
*
* Class: java_lang_ProcessHandleImpl
* Method: destroy0
* Signature: (Z)V
*/
JNIEXPORT jboolean JNICALL
Java_java_lang_ProcessHandleImpl_destroy0(JNIEnv *env,
jclass clazz,
jlong jpid,
jlong startTime,
jboolean force) {
DWORD pid = (DWORD)jpid;
jboolean ret = JNI_FALSE;
HANDLE handle = OpenProcess(PROCESS_TERMINATE | THREAD_QUERY_INFORMATION
| PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
if (handle != NULL) {
jlong start = getStartTime(handle);
if (start == startTime || startTime == 0) {
ret = TerminateProcess(handle, 1) ? JNI_TRUE : JNI_FALSE;
}
CloseHandle(handle); // Ignore return code
}
return ret;
}
You can found it at ProcessHandleImpl_win.c
As you can see both implementations - are simple wrapper on top of the kill and TerminateProcess system calls.