On Mon, 28 Aug 2006 04:55:38 +0200, Esben Stien wrote:
Gordon Beaton <n.***@for.emailwrites:
>$ nohup java MyApp /dev/null 2>&1 &
No. This is not what I'm looking for. This is a hack. I want the
application to detach cleanly like a normal daemon.
Thank you for your help so far, but this is not the correct way;).
A daemon changes its working directory, forks, redirects output
streams to /dev/null, detaches from the controlling terminal by
calling setsid(), and forks again. You'll be hard pressed to
accomplish most of that in Java.
Perhaps what you want is this instead:
$ setsid java MyApp /dev/null 2>&1 &
or
$ ( setsid java MyApp /dev/null 2>&1 & ) &
to get the extra fork.
If that isn't "clean enough" for you, then you need to write your own
Java launcher in C.
/gordon
--
[ don't email me support questions or followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e