Wil*_*ess 3 ajax perl fork exit qx
$SIG{CHLD} = ‘IGNORE’; # or waitpid($pid,0) in the parent process
$pid = fork();
if($pid == 0)
{
close STDOUT; # So that the parent sends the response to the client right away.
@errorMsgs = qx(tar up big directories over 50G…); # This can go on for a few minutes.
if($? ==0) { Send a ‘success’ email } # Is always false ($? == -1)
else { Send a ‘failure’ email }
}
elsif($pid){ sendResponse; waitpid($pid,0) if $SIG{CHLD} != 'IGNORE'; exit;}
Run Code Online (Sandbox Code Playgroud)
由于($ SIG {CHLD} ='IGNORE')设置为-1,因此无法从qx()获取正确的返回码($?)和任何错误消息.如果我删除$ SIG {CHLD}语句,则客户端网页在收到子项之前不会收到来自父级的响应消息.
你得到-1,因为你设置$SIG{CHLD}到IGNORE.通过这样做,你杀死qx了捕获退出代码的能力tar......它会在不通知父母(你的子进程)的情况下死亡.
测试出来很简单:
perl -e '$SIG{CHLD} = "IGNORE"; system("ps"); print "Finished with $?\n";
Run Code Online (Sandbox Code Playgroud)
这给出了-1.
perl -e 'system("ps"); print "Finished with $?\n";
Run Code Online (Sandbox Code Playgroud)
这给出了0.
如果你真的需要$SIG{CHLD} = 'IGNORE',那就$SIG{CHLD} = 'DEFAULT'在你的qx电话之前.
此外,请确保您正在使用完整路径tar(例如/bin/tar),以防您/bin在路径中没有,并且无法执行.但是,我假设没关系,因为你没有说你的tar文件没有被创建.