You'll need to reveal more code, otherwise we can't see what the easiest way is to put in some process monitoring and control. Meanwhile I suggest you (re-)read the process control section of the big camel book*.
(* Update: more precisely: Programming Perl, chapter 15, interprocess communication)