在 Java 中生成一个在 JVM 关闭后仍然存在的进程 [英] Spawn a process in Java that survives a JVM shutdown

查看:15
本文介绍了在 Java 中生成一个在 JVM 关闭后仍然存在的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Java 中生成一个进程(仅在 Linux 下),该进程将在 JVM 退出后继续运行.我怎样才能做到这一点?

I need to spawn a process in Java (under Linux exclusively) that will continue to run after the JVM has exited. How can I do this?

基本上,Java 应用程序应该生成一个更新程序,用于停止 Java 应用程序、更新文件然后再次启动它.

Basically the Java app should spawn an updater which stops the Java app, updates files and then starts it again.

我对 hack & 感兴趣斜线方法来让它工作,如果你有一个更好的设计方案:)

I'm interested in a hack & slash method to just get it working as well as a better design proposal if you have one :)

推荐答案

如果您使用 java.lang.Process 它应该正常工作" - 我不相信生成的进程会在 JVM 退出时死亡.您可能会发现 Ant 库使您可以更轻松地控制生成.

If you're spawning the process using java.lang.Process it should "just work" - I don't believe the spawned process will die when the JVM exits. You might find that the Ant libraries make it easier for you to control the spawning though.

这篇关于在 Java 中生成一个在 JVM 关闭后仍然存在的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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