Re: POE::Wheel::Run::Win32 and Win32::Daemon

[email protected] (Andrew Feren)
Newsgroups perl.poe
Message-ID <[email protected]>
Andreas Altergott wrote:
> Hi,
>
> Andrew Feren wrote:
>   
>> Something like the following will give you better results.
>>
>>        my $pid;
>>        if($pid = fork()) {
>>          print(FOUT "running ($pid)\n");
>>          wait();
>>        } else {
>>          open(FOR, '>>', 'C:\delme-kid.txt');
>>          thread();
>>          close(FOR);
>>          sleep(10);
>>          exit(0);
>>        }
>>     
>
> Thanks for the suggestion, but I do not see why this should give better
> results in combination with Win32::Daemon.  As already described the
> service will get a termination request as soon as the child terminates,
> if you do use fork.  Nevertheless I tested this and it did terminate the
> service after one loop.
>
> The termination request comes from the service control manager.
> Probably it thinks the service terminated.  This doesn't make sense.
> Especially because it tries to tell a service to stop, which in its
> opinion did already stop.  Nevertheless it does so
Did you try the suggested change?

I tried very briefly to get Win32::Daemon working, but it didn't want to 
work for me, so I can't speak to Win32::Daemon issues.  That said your 
original service is exiting after 10 seconds because the *parent* not 
the child is calling exit.  The child is returning immediately because 
it has nothing to wait() for.

 From the docs you cited (emphasis mine):

    To the Perl program that called fork(), all this is designed to be
    transparent. The *parent returns* from the fork() with a
    *pseudo-process ID* that can be subsequently used in any process
    manipulation functions; the /*child returns*/ from the fork() with a
    /*value of |0|*/ to signify that it is the child pseudo-process.

The service control manager has every right to think the service is 
terminated.  You terminate it when you exit after a 10 second wait.

-Andrew
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.