Blaskovicz
Blaskovicz

Reputation: 6170

Dancer Under Plackup and Starman; forking leaves defunct starman processes?

As a follow up to my other question here: Forking to Run Code in a Child Process With Perl's Dancer - how do I fork a request running under plackup/starman/dancer without causing the child to be left in the zombie state?

eg of what I'm trying to do:

post '/handle_data' => sub {

# perform some calculations
...
# store some data
...
fork and return; # parent request
# do some long running tasks
...
exit; # child

};

... causes the starman worker to be recycled, but a leftover plackup process to be defunct.

From perlipc, I have also tried setting $SIG{CHLD} = "IGNORE", but to no avail.

Upvotes: 1

Views: 698

Answers (1)

dlamblin
dlamblin

Reputation: 45371

When forking you'd have the parent process not exit but rather wait for the child pid(s). If I recall fork is either setting a return value or a special variable with the pid of the child; so you need to catch that. Oh and register an $SIG{INT} handler that similarly waits.

You're probably looking to use waitpid.

Upvotes: 2

Related Questions