Re: an update to exec_helper.pl script

[prev] [thread] [next] [Date index for 2005/03/12]

From: Stas Bekman
Subject: Re: an update to exec_helper.pl script
Date: 01:29 on 12 Mar 2005
Igor Shevchenko wrote:
> On Saturday 12 March 2005 02:52, you wrote:
> 
>>Igor Shevchenko wrote:
>>
>>>Hi all,
>>>
>>>Some time ago we had a thread about starting long-running background
>>>processes from mp2. I've found a race condition in our last solution. The
>>>helper background script could be killed by apache cleanup handler before
>>>it had a chance to fork into background and do "setsid". Here's the
>>>script itself:
>>>
>>>===start===
>>>#!/usr/bin/perl -w
>>>use strict;
>>>use warnings;
>>>use POSIX ();
>>>
>>>chdir '/';
>>>
>>>POSIX::setsid;
>>
>>You mean you have moved the setsid call to an earlier phase? so setsid is
>>called before spawn_proc_prog() has returned?
> 
> 
> This is the first part.
> The second is that STDOUT is closed (by re-opening it) only after fork(), and 
> the caller sub (exec_helper) will exit only after subprocess's STDOUT is 
> closed. I think this should close this race condition as the caller 
> subroutine will exit only after the background subprocess is running and is 
> fully detached.

In which case it's probably the best to use waitpid instead and which will 
block the return of the subprocess
http://perl.apache.org/docs/1.0/guide/performance.html#Avoiding_Zombie_Processes
Unfortunately this is probably unix-specific. I wonder how can we make a 
crossplatform API that will do just that, fork a long running process for 
you, so you won't need to write any wrapper hacks.

        -- 
        __________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@xxxxxx.xxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

(message missing)

an update to exec_helper.pl script
Igor Shevchenko 23:29 on 10 Mar 2005

an update to exec_helper.pl script
Igor Shevchenko 00:17 on 12 Mar 2005

Re: an update to exec_helper.pl script
Stas Bekman 00:52 on 12 Mar 2005

Re: an update to exec_helper.pl script
Igor Shevchenko 01:18 on 12 Mar 2005

Re: an update to exec_helper.pl script
Stas Bekman 01:29 on 12 Mar 2005

Generated at 08:39 on 15 Mar 2005 by mariachi v0.52