Java - Linux的Process.destroy()源代码 [英] Java - Process.destroy() source code for Linux

查看:108
本文介绍了Java - Linux的Process.destroy()源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查 Process.destroy()的代码,看看它是如何 kill sa子进程的Linux。

I need to check to code of Process.destroy() to see how exactly it kills a subprocess on Linux.

有谁知道这个方法的作用或链接到它的来源?我检查了 jdk 来源和进程只是一个抽象类而 destroy 方法尚未实现,似乎没有链接到 extends implements <的任何子类code>过程。任何帮助将不胜感激。

Does anyone know what this method does or have a link to it's source? I checked the jdk source and Process is just an abstract class and the destroy method has not been implemented, there seem to be no links to any subclass that extends or implements Process. Any help will be appreciated.

谢谢,

推荐答案

流程管理所有类似的操作都由操作系统完成。因此,JVM必须调用适当的系统调用才能销毁进程。显然,这在操作系统之间会有所不同。

Process management and all the like operations are done by the OS. Therefore, the JVM has to call the appropriate system call in order to destroy a process. This will, obviously, vary between operating systems.

在Linux上,我们有 kill 系统调用来执行此操作 - 或退出如果我们想要终止当前正在运行的进程。当然,JDK源中的本机方法是根据JVM将要运行的操作系统分开的。如前所述, Process 有一个 public void destroy()方法。在Linux的情况下,此方法由 UNIXProcess destroy()方法实现如下:

On Linux, we have the kill syscall to do that - or exit if we want to terminate the currently running process. The native methods in the JDK sources are, of course, separated according to the operating system the JVM is going to run on. As noted previously, Process has a public void destroy() method. In the case of Linux, this method is implemented by UNIXProcess. The destroy() method is implemented pretty much like this:

private static native void destroyProcess(int pid);
public void destroy() {
    destroyProcess(pid);
}

本机方法 destroyProcess() UNIXProcess_md.c ,如下所示:

The native method destroyProcess(), in turn, is defined in UNIXProcess_md.c and looks like this:

JNIEXPORT void JNICALL
Java_java_lang_UNIXProcess_destroyProcess(JNIEnv *env, jobject junk, jint pid)
{
    kill(pid, SIGTERM);
}

其中 kill 是Linux系统调用,其源代码在Linux内核中可用,更准确地说是在文件 kernel / signal.c 中。它被声明为 SYSCALL_DEFINE2(kill,pid_t,pid,int,sig)

Where kill is the Linux syscall, whose source is available in the Linux kernel, more precisely in the file kernel/signal.c. It is declared as SYSCALL_DEFINE2(kill, pid_t, pid, int, sig).

快乐阅读! :)

这篇关于Java - Linux的Process.destroy()源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆