Created
March 10, 2011 11:29
-
-
Save riywo/863968 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $pid = fork; | |
if (!$pid){ | |
local $SIG{TERM} = sub {exit 0}; | |
for(1..5){ | |
print "child process\n"; | |
sleep 1; | |
} | |
exit; | |
} else { | |
sleep 3; | |
die; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $pid = fork; | |
if (!$pid){ | |
local $SIG{TERM} = sub {exit 0}; | |
for(1..5){ | |
print "child process\n"; | |
sleep 1; | |
} | |
exit; | |
} else { | |
local $SIG{__DIE__} = sub { | |
kill 'TERM', $pid; | |
}; | |
sleep 3; | |
die; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $pid = fork; | |
if (!$pid){ | |
local $SIG{TERM} = sub { | |
sleep 2; | |
print "child finish\n"; | |
exit 0; | |
}; | |
for(1..5){ | |
print "child process\n"; | |
sleep 1; | |
} | |
exit; | |
} else { | |
eval{ | |
sleep 3; | |
die; | |
}; | |
if($@) { | |
kill 'TERM', $pid; | |
wait; | |
die "$@"; | |
} | |
} |
親プロセス側で$SIG{__DIE__}
でシグナル送ればやりたいことはできるけど、
それだったらevalでくくってシグナル送った方がいいよね。。。
訂正:perl 5.12でも同じでした!失礼
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is perl, v5.8.8 built for x86_64-linux-thread-multi
でやると、親プロセスでdieしたあとも子プロセスが生き残ってしまう。。
5.12だと子プロセスもdieしてくれるらしい。
さて、5.8.8で親プロセスでdieした時に子プロセスもdie(kill)するにはどうすればいいだろうか。