Reputation: 6170
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
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