私がやること:
- cgiスクリプトへのajax呼び出しを行います。
- Cgiスクリプトはフォークしますが、親はすぐに応答メッセージを返します。
- 子はシステムコールを実行しますが、終了コードとエラーメッセージが必要です。
擬似コード:
$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;}
私の問題:
($ SIG {CHLD} ='IGNORE')が原因で-1に設定されているため、qx()から正しいリターンコード($?)とエラーメッセージを取得する際に問題が発生しました。$ SIG {CHLD}ステートメントを削除すると、子が刈り取られるまで、クライアントWebページは親から応答メッセージを受信しません。