Perl fork and kill - kill(0, $pid) always returns 1, and can't kill the child

后端 未结 6 845
孤独总比滥情好
孤独总比滥情好 2021-01-06 07:16

I am running a perl script on a Linux host. I\'m trying to write a script that forks, where the child starts a program that takes forever and the parent times out after 5 s

6条回答
  •  -上瘾入骨i
    2021-01-06 07:37

    I am also seeing this behaviour, that kill 0 returns true even after the process was gone; I suspected you might be missing a call to waitpid (often done in a SIGCHLD handler) which would result in this, but even after adding it, the kill 0 continues to return true.

    I suggest you use non-blocking waitpid instead of kill (and verify that the process actually does die on a SIGTERM signal - some may not, at least immediately). You may also want to try SIGINT after a while if SIGTERM didn't work, and in the last resort SIGKILL.

提交回复
热议问题