Is it possible to double-fork a process in Java?

放肆的年华 提交于 2019-12-07 12:19:49

问题


I need to double-fork vmware so it doesn't inherit the terminal ID (TTY/pts).

This is what I have so far, but I can't get access to the runtime.exec process to fork another process (which removes the terminal ID).

Runtime runtime = Runtime.getRuntime();
Process proc = runtime.exec("vmware");

Is there a way to "daemonize" in Java?


回答1:


You will need to write a small C or C++ program to do the extra fork, setsid, all that stuff.




回答2:


To make your life easier with this, you essentially need to disconnect the application from the shell by closing the input / output streams that are implicitly connected to the current terminal.

To make this simpler fro yourself, have a look at the akuma project. This would be a cleaner solution in plain Java without any need for C wrappers.

Here is a blog post discussing it.




回答3:


You don't actually need to "double fork" in order to do this, only a single fork is necessary. Then the child should close stdin, out, error and start a new session.



来源:https://stackoverflow.com/questions/2151214/is-it-possible-to-double-fork-a-process-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!