Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 9
    No need for the Java to write the PID, the script can do it as well (echo $! > /var/run/my.pid) Also, since usually only root can write to /var/run you can have the shell script running as root and the daemon run as another user. Commented Apr 6, 2009 at 10:58
  • Except you can't change uid or euid in java, so you have to do it from the shell, with sudo... it's a bit of a pain if you ask me. It's easier to have /var/run and var/log writable to the user you run as... Commented Apr 6, 2009 at 17:01
  • 3
    Also, the rationale for having Java write the pid file / lock file is to have a mean to know whether the initialization phase of the daemon completed successfully (by writing at the end of that phase). Commented Apr 6, 2009 at 17:41
  • 1
    This answer is useless. You want to do the fork AFTER the sockets are created. This just detaches the process from the shell, it's a different thing altogether. Commented Jul 21, 2017 at 9:10
  • The cop-out option won't work -- the thread id is almost certainly not the same as the process id. Commented Aug 6, 2020 at 7:15