作为我在这里的另一个问题的后续:Forking to Run Code in a Child Process With Perl's Dancer -我如何派生一个在plackup/starman/dancer下运行的请求,而不会导致孩子处于僵尸状态?
例如,我正在尝试做的事情:
post '/handle_data' => sub {
# perform some calculations
...
# store some data
...
fork and return; # parent request
# do some long running tasks
...
exit; # child};
..。导致starman worker被回收,但剩余的拼装过程将失效。
在perlipc中,我也尝试过设置$SIG{CHLD} = "IGNORE",但无济于事。
发布于 2012-12-14 11:48:07
在派生时,您应该让父进程不退出,而是等待子进程pid。如果我还记得的话,fork正在设置一个返回值或一个特殊变量,其中包含孩子的pid;所以您需要捕获它。哦,注册一个类似等待的$SIG{INT}处理程序。
您可能正在考虑使用waitpid。
https://stackoverflow.com/questions/13870702
复制相似问题