that's the wrong question.
The real question is why do you have an infinite loop in the if() in the first place.
can you show us the code that does this infinite loop?
exiting an infinite loop after a certain time is basically something like this
...
const unsigned long timeOut = 20000ul; // 20s in ms
unsigned long startTimeBeforeInfiniteLoop = millis();
while (true) { // wannabe infinite loop
... // some code, possibly using break to exit the infinite loop
if (millis() - startTimeBeforeInfiniteLoop >= timeOut) break; // exit the while loop after 20s max
}
I just guess it´s an infinite loop in that part because it could work for weeks and suddenly it stop working. It could even be the communication between Yün Linux-shield and Arduino that´s is the problem. I use #inculde <Bridge.h> and find .releaseBuffer() and see if that could help.
Problem why I can´t see the fault is that i don´t have any computer connected to my Arduino and can monitor the problem when it happens. When I disconnect my USB and connect the computer, it restart and works fine. Because it works in weeks I can´t leave my computer until it happens. Need to try something, one is to brake the loop after x seconds.
If there was Raspberry Pi to buy 2 years ago in sweden, I probably use one with a small screen so I could debug it whitout computer. This was the only one that I could order with RJ45-port. So I am really newbee on the Yün model.
After a software upgrade for our EOS-lighting console it send UDP-commands for every pressed button and every moved fader to my Arduino... for no reason. So it was just to turned that off in the software and it works again.