Re: The daemonize/pty issue

From: Sam Umbach <>
Date: Thu, 21 Apr 2011 18:27:38 -0400

I'll confirm, but my initial tests with nohup were unsuccessful.
Additionally, using nohup on the daemon start will report immediate
success even if the daemon fails to start.

The best solution I've found so far is to immediately call setpgid in
both the parent and child process. Then call fork a second time in
the child, and call setsid in the grandchild (which goes on to become
the daemon). I've never seen this method fail.


On Thu, Apr 21, 2011 at 1:54 PM, Murray S. Kucherawy <> wrote:
> On Thu, 21 Apr 2011, Clint Byrum wrote:
>> Hi everybody. I just joined so apologies for not replying to the thread.
> Seems like you hadn't subscribed yet because we had to approve this
> manually.
>> Scott Kitterman asked me to take a look at the recently discussed issues
>> around daemonizing and letting go of the controlling terminal.
>> I've been able to reproduce it 100% of the time now with this command
>> going from Ubuntu 11.04 beta2 to a VM running Ubuntu 11.04 beta2:
>> ssh -tt ubuntu_at_1.2.3.4 sudo /usr/sbin/opendkim -x /etc/opendkim.conf -u
>> opendkim -P /var/run/opendkim/ -p inet:8891_at_localhost
>> I did have to make sure I had an ssh key and NOPASSWD: ALL on the box for
>> my user so that it would login/exit fast. This reinforces the possibility of
>> a race condition.
>> The child process always dies sometime after that, either before the
>> pidfile is created, or it cleans up the pidfile.
>> I've tried moving the call to 'setsid()' before the calls to dup2 to move
>> stdio to /dev/null. So far that has been unsuccessful, but I'm trying some
>> other things as well.
>> Stay tuned, I think we can actually get this fixed for 11.04's release
>> (crosses fingers).
> Is there some reason use of nohup(1) has been disqualified?  I believe this
> scenario is exactly why that tool was created.
> -MSK
Received on Thu Apr 21 2011 - 22:27:51 PST

This archive was generated by hypermail 2.3.0 : Mon Oct 29 2012 - 23:20:17 PST