通过JNI使用POSIX分支克隆JVM,但是子JVM不会退出 [英] clone a JVM with POSIX fork through JNI, but child JVM will not exit

查看:100
本文介绍了通过JNI使用POSIX分支克隆JVM,但是子JVM不会退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用POSIX fork克隆正在运行的JVM.我可以通过JNI访问fork的方式(即 https://github.com/kohsuke/akuma/blob/master/src/main/java/com/sun/akuma/CLibrary.java ).分叉之后,我希望父母和孩子都进行一些计算,然后退出.

I'm trying to clone a running JVM with POSIX fork. The way I get access to fork is through JNI (i.e. https://github.com/kohsuke/akuma/blob/master/src/main/java/com/sun/akuma/CLibrary.java). After the fork, I'd like both the parent and the child to do some computation and then exit.

以下是测试代码.在分叉之后,我可以看到两行在分叉之后",这意味着父级和子级都达到了这一点.但是然后,父进程正常退出,而子进程没有退出.

The following is the test code. After the fork, I can see two lines of "After the fork.", meaning that both the parent and the child reach this point. But then, the parent process exits normally while the child process doesn't.

此外,我无法在终端中使用信号15终止子进程.我必须使用kill -9来杀死子JVM进程.

Furthermore, I cannot kill the child process with signal 15 in the terminal. I have to use kill -9 to kill the child JVM process.

有什么问题的想法吗?

import static com.sun.akuma.CLibrary.LIBC;

public class ForkTest {
    public static void main(String[] args) {
        int pid = LIBC.fork();
        if (pid == 0) {
            System.out.println("This is the child.");
        } else {
            System.out.println("This is the parent. child pid=" + pid);
        }
        System.out.println("After the fork.");
    }
}

推荐答案

@Awaken 根据本文 http://www.linuxprogrammingblog.com /threads-and-fork-think-twice-before-using-them ,当您分叉多线程应用程序时,只有名为fork()的线程保持活动状态,而其他线程死亡.如果丢失所有线程,我认为您无法在孩子中完成快照.

@Awaken According to this article http://www.linuxprogrammingblog.com/threads-and-fork-think-twice-before-using-them, when you fork a multithreaded application only the thread that called fork() stays alive while other threads die. I don't think you can accomplish the snapshot in the child if you lose all threads.

这篇关于通过JNI使用POSIX分支克隆JVM,但是子JVM不会退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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