Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

Subject: Detach (daemon)

Thread view: 
Esben Stien - 27 Aug 2006 15:21 GMT
Any examples how to detach and run as a daemon?.

I've seen some use System.out.close() and System.err.close(), but I
just can't get it to detach and run as a daemon.

I'm on GNU/Linux, using gcj/classpath.

Any pointers?

Signature

Esben Stien is b0ef@e     s      a            
        http://www. s     t    n m
         irc://irc.  b  -  i  .   e/%23contact
          sip:b0ef@   e     e
          jid:b0ef@    n     n

Gordon Beaton - 27 Aug 2006 18:33 GMT
> Any examples how to detach and run as a daemon?.
>
> I've seen some use System.out.close() and System.err.close(), but I
> just can't get it to detach and run as a daemon.
>
> I'm on GNU/Linux, using gcj/classpath.

The application doesn't need to do anything special, but you need to
run it like this from the shell (actual syntax may vary, but this
example assumes bash):

 $ nohup java MyApp > /dev/null 2>&1 &

/gordon

Signature

[ 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

Esben Stien - 28 Aug 2006 02:11 GMT
> $ 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;).

Signature

Esben Stien is b0ef@e     s      a            
        http://www. s     t    n m
         irc://irc.  b  -  i  .   e/%23contact
          sip:b0ef@   e     e
          jid:b0ef@    n     n

Gordon Beaton - 28 Aug 2006 07:55 GMT
>> $ 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

Signature

[ 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

Domagoj Klepac - 28 Aug 2006 21:44 GMT
>> No. This is not what I'm looking for. This is a hack. I want the
>> application to detach cleanly like a normal daemon.
[quoted text clipped - 5 lines]
>calling setsid(), and forks again. You'll be hard pressed to
>accomplish most of that in Java.

When it comes to Java daemons/services:
http://wrapper.tanukisoftware.org/

               Domchi


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.