If it spwaned any children, I need to hunt them
down and kill them. But I did not want to kill
the master process, since it was a batch file
that cleaned up, copying logs around, etc.
I did not stumble over anything pre-written, so
I came up with this:
\n\nif ((time - $START_TIMES{$id}) > $CURRENT_CHILDREN_TIMEOUT{$id}){\n hunt_down_and_kill_children($id,undef);\n}\n\nsub hunt_down_and_kill_children{\n\tmy $pid = shift;\n\tmy $subs = shift;\n\n\tmy $top_level = 0;\n\n\n\tif (!defined($subs)){\n\t\tmy $pi = Win32::Process::Info->new();\n\t\tmy %subs = $pi->Subprocesses();\n\t\t$subs = \\%subs;\n\t\t$top_level++;\n\t}\n \n\tif (defined($subs->{$pid}) && exists($subs->{$pid})){\n\t\tforeach my $kid (@{$subs->{$pid}}){\n\t\t\thunt_down_and_kill_children($kid,$subs);\n\t\t}\n\t}\n\n\t#\n\t# Do not kill the master batch file since\n\t# it is responsibile for copying files around\n\t# and cleanup.\n\t#\n\tunless ($top_level){\n\t\tWin32::Process::KillProcess($pid,99);\n\t}\n}\n\n
Did I miss something already built to do this?
Is this method dangerous?