Monitor strace in a loop, restart process when error string is matched


I’m using a proprietary app on my Raspberry Pi 4.

The app has a bug where after a certain amount of time it slows to a crawl. It doesn’t fully crash, it just starts performing sub-optimally. The fix is to kill the process and reopen it.

There is a flag in the apps console output I could use to determine that the problem has occurred: "Time taken to process image –249" (249 being the maximum it reports).

Is it possible to set up a .sh file to monitor strace for this process and then kill the process and re-open it? I’ve done plenty of Googling but I am out of my depth.

I would prefer not to write the strace to a text file and then read from that file. The console output from the application updates 60~ times per second and this would quickly ruin the SD card.

My instinct is to loop through the 10 most recent entries in the strace and look for a string match, but I can’t figure our the syntax for that nor if it’s even possible.


How about a fairly naive bash wrapper? Since you’re using strace and we know it’s well behaved when writing to a pipe (it will exit when the pipe stops reading) you should be able to just do something like this:

while strace -vF app 2>&1 | grep -q -m1 -- '--249'
  echo restart 
  sleep X

Adjust the X in the sleep to a suitable value.

Personally I’d ask the maker of the proprietary app to sort their shit out 😉

Answered By – tink

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published