| 38 | | * close(STDOUT)を必要と書かれている文献が多いが、手元の環境(下記)ではSTDINも閉じないと親プロセスは終了しなかった。 |
| 39 | | * 親プロセスについてはSTDIN/STDOUTを閉じた時点でhttpdからプロセスが終了させられるので(see [http://www.bioinfo.jp/tips.html Tips (CGI, Perl, Unix and etc.)])、exit前に何かの処理を行うことは出来ない。 |
| 40 | | * apache2 -V |
| | 40 | * Apache2 mpm-prefork + Perl 5.10 on x64 |
| | 41 | {{{ |
| | 42 | #!perl |
| | 43 | #! /usr/bin/perl -w |
| | 44 | |
| | 45 | my $pid = fork; |
| | 46 | if (! defined $pid) { |
| | 47 | # cannot fork |
| | 48 | die("cannot fork: $!"); |
| | 49 | } |
| | 50 | |
| | 51 | if ($pid) { |
| | 52 | # parent process |
| | 53 | print "Content-type: text/html;\n\n"; |
| | 54 | |
| | 55 | print "parent: $$ / child: $pid\n"; |
| | 56 | } |
| | 57 | else { |
| | 58 | # child proccess |
| | 59 | close(STDOUT); |
| | 60 | |
| | 61 | sleep(60); |
| | 62 | } |
| | 63 | }}} |
| | 64 | * 子プロセスでclose(STDOUT)が必要とだけ書かれている文献が多いが、Apache2 mpm-worker環境では親子ともSTDINも閉じないと親プロセスは終了しなかった。 |
| | 65 | * しかし、テストのため一度mpm-preforkに切り替えた後、再度mpm-workerに戻した後は何故かpreforkと同じ挙動(STDINを閉じなくてもOK)を示すようになった。 |
| | 66 | * apache2 -V |
| | 78 | * Apache2 mpm-preforkでは子プロセスでclose(STDOUT)するだけで良かった。 |
| | 79 | * apache2 -V |
| | 80 | {{{ |
| | 81 | Server version: Apache/2.2.14 (Ubuntu) |
| | 82 | Server built: Apr 13 2010 20:21:26 |
| | 83 | Server's Module Magic Number: 20051115:23 |
| | 84 | Server loaded: APR 1.3.8, APR-Util 1.3.9 |
| | 85 | Compiled using: APR 1.3.8, APR-Util 1.3.9 |
| | 86 | Architecture: 64-bit |
| | 87 | Server MPM: Prefork |
| | 88 | threaded: no |
| | 89 | forked: yes (variable process count) |
| | 90 | }}} |
| | 91 | * 親プロセスについてはSTDIN/STDOUTを閉じた時点でhttpdからプロセスが終了させられるので(see [http://www.bioinfo.jp/tips.html Tips (CGI, Perl, Unix and etc.)])、exit前に何かの処理を行うことは出来ない。 |
| | 92 | * mpm-preforkでは子プロセスが終了するまで、親プロセスはゾンビとして残った。mpm-workerではそのようなことはない模様(こちらも、一度mpm-preforkに切り替えると、workerに戻してもゾンビが残るようになった)。 |
| | 93 | * ps aux | grep www-data |
| | 94 | {{{ |
| | 95 | www-data 3767 0.0 0.0 0 0 ? Z 15:28 0:00 [fork.cgi] <defunct> |
| | 96 | www-data 3768 0.0 0.1 16700 668 ? S 15:28 0:00 /usr/bin/perl -w /var/www/archive/fork.cgi |
| | 97 | }}} |