[Speedycgi-users] Probem of terminating a forked process
Brought to you by:
samh
|
From: Chung-Kie T. <tu...@tu...> - 2003-11-06 16:55:33
|
Hi Sam,
I have found a problem in teminating a forked process while speedycgi is
used.
Here is the example
-example 1-------------------------------
#!/usr/local/bin/speedy
$|=1;
print "parent $$\n";
if (fork()==0) {
print "child $$\n\n";
exit 0;
}
-----------------------------------------
If this script is executed for several times,
we can see all the forked child become zombie,
`-+- 49150 tung /usr/bin/speedy_backend ./t.pl
`-+- 49151 tung /usr/bin/speedy_backend ./t.pl
|--- 49152 tung (speedy_backend)
|--- 49155 tung (speedy_backend)
`--- 49157 tung (speedy_backend)
This behavior is the same as normal daemon process,
then I try to add a handler to catch signal CHLD:
-example 2--------------------------------
#!/usr/local/bin/speedy
$|=1;
$SIG{CHLD}=sub { wait }; # prevent zombie
print "parent $$\n";
if (fork()==0) {
print "child $$\n\n";
exit 0;
}
-------------------------------------------
Then all processes related to this script disappear.
This makes think if I should only change a local copy of $SIG{CHLD}
-example 3--------------------------------
#!/usr/local/bin/speedy
$|=1;
local $SIG{CHLD}=sub { wait }; # prevent zombie
print "parent $$\n";
if (fork()==0) {
print "child $$\n\n";
exit 0;
}
-------------------------------------------
And the result is the same as example 1,
all child processes become zombies.
Only example 2 won't make zombies but the process won't be persistent.
So my question is how to terminate a forked processed in a speedycgi-enabled
program?
Regards.
tung
--
Distributed System Laboratory (http://dslab.ee.ncku.edu.tw)
Department of Electrical Engineering
National Cheng Kung University, Tainan, Taiwan, R.O.C.
|