0

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?

codeforester
  • 39,467
  • 16
  • 112
  • 140
Lorccan
  • 793
  • 5
  • 20
  • 1
    The third question (quit process after timeout) has an answer here: http://stackoverflow.com/questions/5161193/bash-script-that-kills-a-child-process-after-a-given-timeout – Andrea Corbellini Feb 07 '16 at 14:48
  • 1
    The second question (check file and quit after some time) can be done with a simple `for`/`while` + `sleep` + `[ -f ... ]` + `kill` – Andrea Corbellini Feb 07 '16 at 14:50
  • Thanks. Those both look like useful things for me to work with. – Lorccan Feb 07 '16 at 14:52

1 Answers1

1

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.

Umamahesh P
  • 1,224
  • 10
  • 14
  • It's a 3rd party's, so I have to work around the problem. I suppose the problem is that I can't grasp how - if the process is not completing - I can get to the point of monitoring and killing it, but I think I need to look at what http://stackoverflow.com/users/1913824/andrea-corbellini provided to see whether I can make it work. – Lorccan Feb 07 '16 at 14:54
  • you can use the "SECONDS" variable to measure the timeout. Example is here. http://stackoverflow.com/questions/5152858/how-can-i-measure-a-duration-in-seconds-in-a-linux-shell-script – Umamahesh P Feb 07 '16 at 14:59
  • Thanks. This makes it easy to show what I don't understand: if I 1. start the time logging, 2. do something, 3. stop the logging (and calculate interval), how do I get to do 3. if 2. never completes? – Lorccan Feb 07 '16 at 15:02
  • Run the process in the backaground. – Umamahesh P Feb 07 '16 at 15:03
  • Ah! Got it! Simple really. Thanks for your patience. – Lorccan Feb 07 '16 at 15:04