Monitoring for a hung process

A coworker has a shell script that runs from a scheduler at the 3am. The shell script runs sqlplus passing in a sql statement, which generate a file. This is done 21 times for 21 different sql statements. Recently, one of the sqlplus processes got hung.

Is there a way to monitor how long the shell script takes to run, and kill it if it takes longer than, lets say, an hour. Or to monitor the time the individual sql's run?

Assuming you can't spawn these off to separate shells where you would:

thatprog &
$progid=$!
sleep $sleeptime
kill $progid

But if you need to be doing other stuff in between, generally you'd capture the PID's of the processes when they start, then watch for those processes still running ("ps -p $pid" if you are using shell), killing them when your conditions dictate.

You might also be able to use "ulimit -t" to set maximum cpu time used if that makes sense.

--
Tony Lawrence
Unix, Linux, Mac OS X Help, Tutorials and support pages

Thanks Tony. I'll check with my coworker on Monday. I haven't seen the script yet, just an email looking for help.