It might be better to find the root cause of the processes going out of control, but to find any process in state S but using some amount of CPU one could use a script along the lines of:
#!/usr/bin/env bash
ps ahxo pid,state,%cpu |\
while read pid state cpu; do
if [[ "$state" = S ]]; then
if [[ "${cpu%%.*}" -gt 90 ]]; then
echo "woe betide pid $pid"
fi
fi
done
with a kill instead of the echo once you are sure the script is not going to destroy your system. This could be made less dangerous by restricting the match based on the command field, or by first filtering for suitable PID with the pgrep command. "More than 2 hours" is difficult to capture from the ps output given that time is humanized; parsing that information out of /proc/$pid/stat can be dangerous if whitespace ever shows up in the process name. Or the monitoring script could be made more complicated and maintain a state counter for how many times it has seen a PID with the required conditions. Maybe see if the above script works, first, before going for a more complicated "more than 2 hours" check?
Another method might be to have a monitoring system that makes periodic requests to the service, and to have that issue a service restart if the requests start timing out or taking too long. But such band-aids aren't really a good long term solution for something that needs to be whacked with a broom now and then.
If the service has some sort of log file indication that things are broken, that can be another method to automatically detect faults and "turn it off and back on again."
Of course such restart automation can go terribly wrong if it kills the wrong process, or kills the process when it should not; this might be used as a rationale for finding and fixing the problem, or retiring the software, in the event management is not willing to spend the necessary resources to fix the problem. I've had */5 * * * * /reboot-service crontab jobs because something management wouldn't allow to be fixed was leaking that much memory... oh yeah you probably want to document the auto-restart script somewhere, to disable it when doing updates, and so on. More work.