Fixed PID forgetfulness.

Without this change the daemon would report its PID as 0 for me. Writing the PID file before the parent is exited fixes this behavior.