views:

221

answers:

3

I am trying to decide as to whether to use ProcessBuilder or Commons exec, My requirements are that I am simply trying to create a daemon process whose stdout/stdin/stderr I do not care about. In addition I want to execute a kill to destroy this process when the time comes. I am using Java on Linux. I know that both have their pains and pitfalls (such as being sure to use separate thread to swallow streams can lead to blocking or deadlocks, and closing the streams so not to leave open files hanging around)and wanted to know if anyone had suggestions one way or the other as well as any good resources to follow.

A: 

commons-exec is not the best library I've ever used but it does solve the biggest pitfall in Java process invocation which is handling/consuming stdout/sterr properly. I've used ProcessBuilder in the past, which is fine, and commons-exec now which is also fine and handles most of the common cases easily.

Mike Q
A: 

If you want to use a daemon process, maybe Apache Commons Daemon would be more appropriate?

mlaverd
A: 

Commons Daemon does the job of starting a Java process as a daemon, but it doesn't do it the way one would expect. For example, when a standard C program starts a daemon (take apache or sshd for example), they perform some config sanity checks and other things (like locking a lockfile) before forking into the background. Apache Commons Daemon is a c program that launches a java app and doesn't let you put the sanity checks in the Java code AFAIK and thus breaks what I would consider important daemon facilities.

Thus, if you are looking to implement a daemon launcher that behaves similar to sshd, apache, etc. then I would suggest commons exec.

jeckhart