in reply to How to kill an external program

You could fork off a child and call exec from that child. Then you could use the PID from fork to call kill. Thus:
if($pid = fork() == 0) { exec("command"); } # this is all executed in the parent ... kill $pid;