Perl pipe hangs and process becomes defunct

时间:2018-12-19 11:16:51

标签: perl pipe

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.

1 个答案:

答案 0 :(得分:3)

程序退出时,它将变成僵尸(已消失的进程),直到其父进程(通过调用wait收割)。 [1] 如果该进程完全消失,则程序不会无法获得子进程的退出代码。这是完全正常的,不是问题。

  1. 孤儿(包括僵尸孤儿)被过程1收养,过程结束后立即收割其子代。