Script to Kill process which is in hang state

Hi,

Can anyone help to create a script that will kill the process which is in hang state.

If the process is not a zombie this will work.
Get the pid of the process then pretend the result is 1234

kill 1234

Some other folks may suggest kill -9 [pid]. This is a bad idea and is a last resort. Why?
kill -9 prevents the process from cleaning up, assuming it is a reasonable unix application. This may leave some file, a semaphore, or some other object in a bad state, such that the application may fail next time.