|more useful options
Problems with forkingby mraspberry (Initiate)
|on Apr 02, 2011 at 01:16 UTC
mraspberry has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks, any help with a vexing issue I am having would be appreciated. I'm trying to write a program that will basically act as a daemon (no networking component, just run continuously disconnected from a shell). I'm not too familiar with forking though nor have I ever written anything like this in any other language. So I decided to write a short program to work out this issues I've been having with it but I can't get that to do what I want either. I'm using perl 5.10.1. The logic I am using to create the daemon is as follows: !) Fork 2) close the parent 3) fork the child 4) close the child and run your code in the grandchild Here is the code I'm having trouble with:
So everything runs fine until it gets to the grandchild. For some reason it doesn't seem to be doing anything after opening the filehandle (I'm used to checking for filehandle open errors with die but I wasn't sure what would happen if a message from a grandchild process no longer connected to a parent or grandparent got printed to STDERR. Anyway, the message never gets printed to the daemon.test file nor does the grandchild ever exit. What am I missing?