2 ms·
I have a thing that I only wrote in bash as a stunt to see if I could. It interacts with a hardware device over rs232, and the protocol is all polling and timeo
by Brian_K_White 2y ago
I have a thing that I only wrote in bash as a stunt to see if I could. It interacts with a hardware device over rs232, and the protocol is all polling and timeouts. So it needs to sleep for short durations many bezillion times, and bash has no built-in sleep like ksh does, and I don't want the script to rely on plugins. So....
_sleep () {
read -t ${1:-1} -u 4 ;:
}
readonly sleep_fifo="${XDG_RUNTIME_DIR:-/tmp}/.${0//\//_}.${LOGNAME:-$$}.sleep.fifo"
[[ -p ${sleep_fifo} ]] || mkfifo -m 600 "${sleep_fifo}" || abrt "Error creating \"${sleep_fifo}\""
exec 4<>${sleep_fifo}