Earlier quoted context omitted.
Recently I found myself wanting to stop a program after a certain timeout. I found myself thinking "sure there's a UNIX program to do this in shell?" There is. And it's called... brace yourself... "timeout". 20+ years in UNIX, never encountered it. Part of GNU coreutils.
Sometimes good to use for cron jobs so that the previous one won't keep running on top of the current run. You should debug for it to not happen though but probably better than seeing your system choke with dozens of instances even slowing the jobs more. There's also "run-one" that allows you to control which job should survive instead of just killing the old one. http://manpages.ubuntu.com/manpages/trusty/man1/run-o…
(Of course, this can be surprising in a different way when you expect a new job to start, but it does not because a previous one is still lingering. Not saying it's better or worse, just pointing out for those who don't know.)