473,324 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Subject: Detach (daemon)

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?

--
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
Aug 27 '06 #1
4 5418
On Sun, 27 Aug 2006 18:07:12 +0200, Esben Stien wrote:
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

--
[ 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
Aug 27 '06 #2
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;).

--
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
Aug 28 '06 #3
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
Aug 28 '06 #4
On 28 Aug 2006 08:55:14 +0200, Gordon Beaton <n.***@for.emailwrote:
>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.
When it comes to Java daemons/services:
http://wrapper.tanukisoftware.org/

Domchi
Aug 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Rob Hunter | last post by:
Hi all. I want to run a Python daemon that manages a "to-do" queue. I want it so that the daemon is always running, where its running consists of looking at the queue to see if it has any jobs,...
3
by: bmgx | last post by:
This is what I am trying to find out, instruction on how to create a simple daemon on unix systems(Linux), can't find any info on usual sources..
1
by: Bob Swerdlow | last post by:
I've created a Python daemon that starts a bunch of BitTorrent downloader process. Everything is working fine when I start the daemon by hand (logged on as root). I can quit the session and see...
7
by: Michael Ransburg | last post by:
Hi! I have implemented a daemon in C++. It runs all the time, between reboots. Is there a way for other C++ classes to get a reference to the instance of this daemon class in order to call its...
1
by: Stefan Neumann | last post by:
I have written a daemon which should run endlessly. The structure looks like this: - start-stop-daemon forks my python program then: if __name__=="__main__": try: main()
2
by: =?Utf-8?B?Um9nZWxpbw==?= | last post by:
so I notice to detach a database you use Server svr = new Server(); svr.DetachDatabase("MyDatabase"); but is there a way you can set where its saved after detaching ? thansk
3
by: paul | last post by:
I am writing a daemon process that reads data from the serial port / dev/ttyS0. I am using pyserial & the method for setting up a daemon described in "Chris' Python Page"...
6
by: Johny | last post by:
Is it possible to run a Python program as daemon? Thanks
9
by: dpatel75 | last post by:
I am trying to copy a database from a SQL 2000 SP3 Windows 2000 server to a 2005 SP2 Windows 2003 server. I am trying to use detach and attach method (have tried both within Management Studio and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.