Here are some bash scripts and a program called timelimit which may solve your problem.
Kill process after it’s been allowed to run for some time
EDIT: I think I found a better solution. Try using the timeout program. From the man page:
“timeout – run a command with a time limit”. For example:
timeout 5s sleep 10s
It basically runs your command and after the specified duration it will kill it.