This useful little tool checks for changes in GPIO state without periodic polling by using the interrupt interface provided by Linux. It's useful in scripts to wait for a state change with Raspberry Pi, but works with any hardware with GPIOs.
Public domain.
To make this work, you need to export the pin and then enable interrupts. For example:
echo 24 >/sys/class/gpio/export
echo both >/sys/class/gpio/gpio24/edge
Then just run gpio_wait 24 0
to wait for the state to turn to LOW state (or 1 for HIGH).
gcc -Wall -O2 -o gpio_wait gpio_wait.c