You might be able to do it with a spinlock.. you can hold a lock on your prog and repeatedly check whatever you want
for example u can use jiffies or something, so that if it loops for like 1-2 secs you can release lock or whatever
links i jumped into:
http://en.wikipedia.org/wiki/Spinlock
http://linux.ubuntu.com.tw/2008/04/linux-kernel-spin-locks-vs-semaphores.html
http://www.linuxgrill.com/anonymous/fire/netfilter/kernel-hacking-HOWTO-5.html