views:

153

answers:

3

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?

+3  A: 

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

bmargulies
+1 - and note that the reason that Java does not support this explicitly is that the relevant concepts are operating system specific.
Stephen C
ok, that's what I thought, I just wanted to make sure there wasn't a better way.
Robert Greiner
Shell script, perl, python etc, would also do.
MarkR
A: 

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.

gpampara
A: 

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.

MarkR
+1 if this works. I haven't tested it myself.
Alfred
Look at what daemon() does
MarkR