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
From perldoc fork:
If you fork without ever waiting on your children, you will accumulate zombies. On some systems, you can avoid this by setting $SIG{CHLD} to "IGNORE" .
I was able to get the desired behavior when adding $SIG{CHLD} = 'IGNORE';
to the top of your code.
[ben@imac ~]$ perl test.pl
numKilled: 1
[ben@imac ~]$
Alternatively, adding waitpid($childPid, 0);
after kill
did the trick as well.