Sujet : Re: [ksh93u+m] alarm timer function
De : richard.nospam (at) *nospam* gmail.invalid (Richard Harnden)
Groupes : comp.unix.shellDate : 17. Mar 2024, 21:25:22
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <ut7jji$3n956$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
On 17/03/2024 20:01, Kaz Kylheku wrote:
On 2024-03-17, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
The program 'busy' could be something like
>
$ cat ~/bin/busy
typeset busy='/-\|'
typeset -i i=0
alarm -r timer +0.25
function timer.alarm { print -u2 -f "%c\b" -- "${busy:i++%4:1}" ;}
( "$@" & wait )
unset timer
>
with 'alarm' and 'timer.alarm' used as supported by ksh93u+.
>
I suppose the 'at' command is not suited for such purposes.
Remember how I rigged something up in the Basta project to spontaneously
update the clock in the status line, while the shell is waiting for
input or running scripts?
Forked process periodically killing parent with signal, which has a trap
handler for it.
kill -0 <pid> asks ksh whether that process is still running (rather than actually sending a signal), so something like ... ?
function busy
{
BUSY_PROG=$1
shift
${BUSY_PROG} $@ &
BUSY_PID=$!
while :
do
kill -0 ${BUSY_PID} 2>/dev/null || break
echo -n .
sleep 1
done
wait %1
return $?
}