Search code examples
bashtimeoutterminate

Timeout for a stuck process


I am calling a video conversion process in a do ... while that's looping over a set of files.

Most of the time it works as expected, but occasionally the process gets hung-up on a file and doesn't move on until I kill it. (So it's not unresponsive as such - just useless!)

It's still sending to stdout and stderr, where I can see that it's attempting to read the same index over and over. I can also see that it's not writing any output to a destination file (so it's not doing anything useful).

Can I:

  • monitor stdout and/or stderr for repetitive items and quit the process if it does it more than a number of times; or

  • monitor for the destination file and quit the process if it doesn't exist after a timeout; or

  • quit the process if it fails to complete after a timeout?


Solution

  • If the video conversion process is developed by you then the best solution would be to fix infinite loop problem. From an error handling perspective or if the process is 3rd party one, then you can redirect the output to a file and then periodically checks the file for specific errors messages from the log and then kill it. If the process is expected to process a file on a specific time frame, then you can kill the process if the conversion is not completed in the specified time frame.