I have a perl script that executes another script using pipe:
$pid = open (OUTPUT, "my_script.pl 2>&1 |") || "";
if ($pid) {
while (<OUTPUT>) {
print;
}
close (OUTPUT);
}
my_script.pl
forks another child process. When I first kill my_script.pl
and then kill its child process (I kill the processes manually using kill -9
), then my_script.pl
process becomes a defunct and the pipe hangs.
Any idea how to solve this issue?
I don't want to kill the child process first.
答案 0 :(得分:3)
程序退出时,它将变成僵尸(已消失的进程),直到其父进程(通过调用wait
收割)。 [1] 如果该进程完全消失,则程序不会无法获得子进程的退出代码。这是完全正常的,不是问题。