Created
January 23, 2014 02:07
-
-
Save drinkcat/8571526 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo "Send signals from another console:" | |
echo "kill -USR1 $$" | |
SIG='force' | |
trap "SIG='USR1'" USR1 | |
# Create a dummy FIFO. Reading the FIFO will block until interrupted by a signal | |
SIGFIFO="clip.fifo" | |
if [ ! -p "$SIGFIFO" ]; then | |
rm -f "$SIGFIFO" | |
mkfifo -m 400 "$SIGFIFO" | |
fi | |
while true; do | |
echo "SIG='$SIG'" | |
if [ -z "$SIG" ]; then | |
echo "Waiting..." | |
# Redirect stderr to /dev/null to avoid "Interrupted system call" | |
# messages. Save stderr to fd 3 so we can restore it later. | |
exec 3>&2 2>/dev/null | |
# Block until a signal is received | |
read < "$SIGFIFO" || true | |
exec 2>&3 3>&- | |
fi | |
# This is _not_ a potential race: the current display is read after this. | |
SIG='' | |
echo "Doing some work..." | |
sleep 3 | |
echo "Done." | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment