This is getting a little bit away from mysql but the easy way to do this is:

use Proc::Daemon; # Available at a CPAN near you :-)
...
Proc::Daemon::Init;

which takes care of all the details of daemonizing your program.

But this still doesn't explain (at least to me) the lost connection.

Unless the $dbh was created before daemonizing and the child process closed the connection on exiting.




Mark wrote:

----- Original Message -----
From: "Rick Robinson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, December 24, 2002 12:03 PM
Subject: RE: SOLVED! (was: Re: What is wrong with this query?)


It's not a true daemon ...

No. It is only called a zombie if the child was brutally cut off from the
parent. If the parent/child take appropriate action, the stand-alone child
is called a daemon (if it waits for connections, of course). That is, the
parent closes its terminals and forks; the child, in turn, still has one
step to perform: it needs to become a session leader, so that it becomes a
parent himself. That is done with the "POSSIX::sessid ()" call. This is a
pretty standard way in Perl to daemonize.


Mike's comment on using a wait or waitpid is valid.

No. "wait" and "waitpid" are only useful when you want to wait for your
children. That does not apply here. The sole function of the parent here is
to close its terminals, fork, and write the child's PID to a file; after
that, it can exit, and the daemonized child remains running.


Your process is still associated with
a terminal and is not the process group leader and is not the session
leader.

You are mistaken on all counts. All terminals were closed, and the program
is certainly a session leader. Let me show what the daemonized "child"
(really a parent now) looks like in "ps -auxr":

news 34 0.0 1.1 12276 11580 ?? Ss 2:05PM 0:23.22 /usr/local/bin/news.pl

As you can see from the flags ("Ss"), this process is no longer a child, but
a sleeping ("S") session leader ("s"). And it has no terminals associated
with it ("??").

If I do a "ps -alxr", its PPID (Parent Process Id) is 1, the 'init' process.
With the exception of being a child of the init process (like pretty much
every other process), the child is fully stand-alone.

I am not sure how to go about in C, but this is how it is done in Perl.

- Mark


---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


---------------------------------------------------------------------
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to