0

I've written some code which daemonizes a PHP shell script. It forks the process into the background, kills the parent process, and handles signals for killing the child process.

This all works great, however, STDERR, and STDOUT are still attached to my shell session. What I'd like to do is, within the child process, the equivalent of calling my script with ./myDaemon.php start 2>&1 > /dev/null without having to to the redirection (in case the parent process needs to output something if the daemonization process fails).

Is this possible?

This will be running on a Linux system, though an interoperable solution would be ideal.

v4nz
  • 115
  • 7
  • 1
    As noted in the linked duplicate: you can close the streams without a problem, you can't repoint them though, that would have to be in the calling codes logic. However, if you _need_ it in PHP, you can... start a PHP script with PHP with stdout/stderr pointing to the right locations. Expect some overhead ;) – Wrikken Dec 05 '14 at 01:02
  • I'm a little disappointed I didn't find that question on my own. Regardless, thank you. I will give this a go. My backup plan was, indeed, to write a wrapper php script and simply redirect the stream when I trigger my daemon, but this should be much better. – v4nz Dec 05 '14 at 01:15
  • Hm, actually... I read repointing _is_ possible with the answer there, BUT: if not found in the docs, I would not rely on the behavior as it may change in any version. – Wrikken Dec 05 '14 at 01:29

0 Answers0