[dancer-users] How can a fork+system() Dancer app not create zombie processes?

Stefan Hornburg (Racke) racke at linuxia.de
Mon Apr 3 11:42:03 BST 2017


On 04/03/2017 12:22 PM, Shlomi Fish wrote:
> Hi Andy!
> 
> On Mon, 3 Apr 2017 09:15:37 +0100
> Andrew Beverley <andy at andybev.com> wrote:
> 
>> On Mon, 3 Apr 2017 11:01:23 +0300 Shlomi Fish wrote:
>>> When running a simple and reduced Dancer 1 application which forks
>>> and runs perldoc -f system , I am getting many zombie processes after
>>> making requests.  
>>
>> Forking a web app is not as simple as it first seems. 
> 
> Do you mean forking any web app or just Dancer apps? 
> 
>> You need to take
>> an approach like the following (hopefully the comments will explain
>> without me regurgitating here, but feel free to ask for clarification):
>>
>> https://github.com/ctrlo/GADS/blob/cb8c9478dee8eac1f40a44486634173bed8d666d/lib/GADS/Record.pm#L1068
>>
> 
> I don't understand the code there in part because it uses too many custom APIs
> like "guard"s and "try". Furthermore, the licence is the AGPLv3 which cannot be
> used inside my MIT Expat code.
> 

Shlomi, the point is the double fork - I suggest to disregard the code in the second
else condition and put your code there :-).

Regards
         Racke

> If someone can provide a simple interface to spawn a background child process
> in Dancer, I will appreciate it. Something like:
> 
> use Dancer::Plugin::SpawnProc;
> 
> # Inside the handler:
> dancer_spawn_proc (sub {
> 	# I am the child process.
> 	system("mpv", 'no-exist.webm');
> 	exit(0);
> });
> 
> ==========
> 
> Regards,
> 
> 	Shlomi Fish
> 
>> The key point being that you need to fork both a child and a
>> grand-child in order to correctly reap all the forked processes.
>>
>> Andy
> 
> 
> 


-- 
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration.


More information about the dancer-users mailing list