Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    running program as a daemon

    i am trying to daemonize my (java) program on ubuntu.
    For that end i created a script based on /etc/init.d/skeleton script which obviously uses start-stop-daemon.

    I put the script to /etc/init.d
    I added symbolic link to it for the runlevel 2.

    But I cannot make the process (java program) run on the background. it keeps running in the same terminal i start my daemon script. Trying --background option for start-stop-daemon does not help.
    This is a remote server to which i can only login via telnet.
    Any ideas what is missing here?


  2. #2
    Linux User
    Join Date
    Nov 2008
    Tokyo, Japan
    All daemons behave like that, its completely normal behavior.

    A daemon is just an ordinary program, and it is up to the programmer to designed the daemon program to ignore the standard input and standard output. So if your program does not explicitly call System.out.close() and System.err.close(), all output produced by your program will continue to flow to these file handles. And the input/output/error file handle for ALL programs, daemon or not, is the terminal which executed it.

    So it may run in the background, but if it produces output, your terminal is still receiving that output. You can try this in a Bash command line:
    java MyDaemon &>/dev/null  &
    This forces all output to be deleted immediately. The "disown" is a Bash command that tells the most recently executed background program to continue running even after Bash exits. If you don't "disown" the daemon, your daemon will receive a "SIGHUP" when Bash exits, and this signal will exit (unless you explicitly told Java not to do this).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts