• [ksh93u+m] alarm timer function

    From Janis Papanagnou@21:1/5 to All on Sun Mar 17 15:48:21 2024
    In ksh93u+ I'm using the built-in 'alarm' timer command.

    $ alarm --man
    Usage: alarm [-r] [varname seconds]

    (The original 'alarm' feature may have been experimental
    and not documented well, but it was nonetheless useful.)

    Just noticed in ksh93u+m that the 'alarm' timer command
    doesn't seem to be available; I now get errors like
    "alarm: not found"
    and
    timer.alarm: invalid discipline function

    Is there some substitute in ksh93u+m that will replace
    that function from the original ksh? (Or something else
    to do to get it working?) Or has that feature just been
    abandoned in the "u+m" branch?

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David W. Hodgins@21:1/5 to Janis Papanagnou on Sun Mar 17 13:49:49 2024
    On Sun, 17 Mar 2024 10:48:21 -0400, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    In ksh93u+ I'm using the built-in 'alarm' timer command.

    $ alarm --man
    Usage: alarm [-r] [varname seconds]

    (The original 'alarm' feature may have been experimental
    and not documented well, but it was nonetheless useful.)

    Just noticed in ksh93u+m that the 'alarm' timer command
    doesn't seem to be available; I now get errors like
    "alarm: not found"
    and
    timer.alarm: invalid discipline function

    Is there some substitute in ksh93u+m that will replace
    that function from the original ksh? (Or something else
    to do to get it working?) Or has that feature just been
    abandoned in the "u+m" branch?

    I'm not a ksh user, so don't know much about it. I recommend using the package "at" for setting alarms and it's not shell dependent.

    Regards, Dave Hodgins

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to David W. Hodgins on Sun Mar 17 19:15:11 2024
    On 17.03.2024 18:49, David W. Hodgins wrote:
    On Sun, 17 Mar 2024 10:48:21 -0400, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    In ksh93u+ I'm using the built-in 'alarm' timer command.

    $ alarm --man
    Usage: alarm [-r] [varname seconds]

    (The original 'alarm' feature may have been experimental
    and not documented well, but it was nonetheless useful.)

    Just noticed in ksh93u+m that the 'alarm' timer command
    doesn't seem to be available; I now get errors like
    "alarm: not found"
    and
    timer.alarm: invalid discipline function

    Is there some substitute in ksh93u+m that will replace
    that function from the original ksh? (Or something else
    to do to get it working?) Or has that feature just been
    abandoned in the "u+m" branch?

    I'm not a ksh user, so don't know much about it. I recommend using the package
    "at" for setting alarms and it's not shell dependent.

    Thanks for the suggestion. It reminds me that I obviously
    should have made the use case clear, where and how I want
    to use the timer. For example; I want to display a turning
    "wheel" (or maybe a growing bar) while some operation is
    in progress. I might use such a timer in a program called
    'busy'. And instead of calling

    $ long_running_process arguments

    I'd call it as

    $ busy long_running_process arguments

    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.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David W. Hodgins@21:1/5 to Janis Papanagnou on Sun Mar 17 14:33:59 2024
    On Sun, 17 Mar 2024 14:15:11 -0400, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    On 17.03.2024 18:49, David W. Hodgins wrote:
    On Sun, 17 Mar 2024 10:48:21 -0400, Janis Papanagnou
    <janis_papanagnou+ng@hotmail.com> wrote:

    In ksh93u+ I'm using the built-in 'alarm' timer command.

    $ alarm --man
    Usage: alarm [-r] [varname seconds]

    (The original 'alarm' feature may have been experimental
    and not documented well, but it was nonetheless useful.)

    Just noticed in ksh93u+m that the 'alarm' timer command
    doesn't seem to be available; I now get errors like
    "alarm: not found"
    and
    timer.alarm: invalid discipline function

    Is there some substitute in ksh93u+m that will replace
    that function from the original ksh? (Or something else
    to do to get it working?) Or has that feature just been
    abandoned in the "u+m" branch?

    I'm not a ksh user, so don't know much about it. I recommend using the
    package
    "at" for setting alarms and it's not shell dependent.

    Thanks for the suggestion. It reminds me that I obviously
    should have made the use case clear, where and how I want
    to use the timer. For example; I want to display a turning
    "wheel" (or maybe a growing bar) while some operation is
    in progress. I might use such a timer in a program called
    'busy'. And instead of calling

    $ long_running_process arguments

    I'd call it as

    $ busy long_running_process arguments

    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.

    For that use case, I'd use a loop in a separate script with "sleep 0.5s". Have the main script start it in the background, and kill it when the process is done.
    The script containing the loop could create a pid file so the main script knows what process to kill, or have the main script create a temp file, pass the name to the loop script, and have the loop script exit after the main script deletes the temp file.

    Regards, Dave Hodgins

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Janis Papanagnou on Sun Mar 17 20:01:42 2024
    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.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Harnden@21:1/5 to Kaz Kylheku on Sun Mar 17 20:25:22 2024
    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 $?
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Kaz Kylheku on Mon Mar 18 06:51:40 2024
    On 17.03.2024 21: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.

    Yes, I remember. There's a couple options to solve such a task. In case
    I have a simple built-in method available I'd prefer that, though.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to David W. Hodgins on Mon Mar 18 06:48:29 2024
    On 17.03.2024 19:33, David W. Hodgins wrote:
    On Sun, 17 Mar 2024 14:15:11 -0400, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

    On 17.03.2024 18:49, David W. Hodgins wrote:
    On Sun, 17 Mar 2024 10:48:21 -0400, Janis Papanagnou
    <janis_papanagnou+ng@hotmail.com> wrote:

    In ksh93u+ I'm using the built-in 'alarm' timer command.

    $ alarm --man
    Usage: alarm [-r] [varname seconds]

    (The original 'alarm' feature may have been experimental
    and not documented well, but it was nonetheless useful.)

    Just noticed in ksh93u+m that the 'alarm' timer command
    doesn't seem to be available; I now get errors like
    "alarm: not found"
    and
    timer.alarm: invalid discipline function

    Is there some substitute in ksh93u+m that will replace
    that function from the original ksh? (Or something else
    to do to get it working?) Or has that feature just been
    abandoned in the "u+m" branch?

    I'm not a ksh user, so don't know much about it. I recommend using the
    package
    "at" for setting alarms and it's not shell dependent.

    Thanks for the suggestion. It reminds me that I obviously
    should have made the use case clear, where and how I want
    to use the timer. For example; I want to display a turning
    "wheel" (or maybe a growing bar) while some operation is
    in progress. I might use such a timer in a program called
    'busy'. And instead of calling

    $ long_running_process arguments

    I'd call it as

    $ busy long_running_process arguments

    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.

    For that use case, I'd use a loop in a separate script with "sleep
    0.5s". Have the main script start it in the background, and kill it
    when the process is done. The script containing the loop could create
    a pid file so the main script knows what process to kill, or have the
    main script create a temp file, pass the name to the loop script, and
    have the loop script exit after the main script deletes the temp
    file.

    Yes, I am aware of several methods (like the one you describe or other)
    how to tackle the task. I prefer a simple and built-in method, though.

    I admit that I am spoiled on that since I had that feature available
    in the past, and losing an option and substitute it by other (complex)
    ways is something not appearing appealing. :-/

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arti F. Idiot@21:1/5 to Janis Papanagnou on Mon Mar 18 08:14:30 2024
    On 3/17/24 11:51 PM, Janis Papanagnou wrote:
    On 17.03.2024 21: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.

    Yes, I remember. There's a couple options to solve such a task. In case
    I have a simple built-in method available I'd prefer that, though.

    Janis


    I think several OSes have a tool called 'progress' which sort of
    functions as you've described; NetBSD does natively. Having it built-in
    would be better though. Was 'alarm' removed in ksh93? I don't see it
    on the NetBSD pkgsrc version.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Arti F. Idiot on Mon Mar 18 16:06:02 2024
    On 18.03.2024 15:14, Arti F. Idiot wrote:

    I think several OSes have a tool called 'progress' which sort of
    functions as you've described; NetBSD does natively.

    Oh, I wasn't aware that there's some OS specific standard for that.

    Having it built-in would be better though. Was 'alarm' removed in
    ksh93?

    It was (still is) there in [official] ksh93u+. That was the version
    I predominantly used on my platforms.

    Meanwhile I've replaced the "u+" version by Martijn Dekker's "u+m"
    version. (The latter has less bugs and works much more reliable.)
    It's just my recent switch that made me notice that in his branch
    there's no 'alarm' available any more.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arti F. Idiot@21:1/5 to Janis Papanagnou on Mon Mar 18 11:10:14 2024
    On 3/18/24 9:06 AM, Janis Papanagnou wrote:
    On 18.03.2024 15:14, Arti F. Idiot wrote:

    I think several OSes have a tool called 'progress' which sort of
    functions as you've described; NetBSD does natively.

    Oh, I wasn't aware that there's some OS specific standard for that.

    Having it built-in would be better though. Was 'alarm' removed in
    ksh93?

    It was (still is) there in [official] ksh93u+. That was the version
    I predominantly used on my platforms.

    Meanwhile I've replaced the "u+" version by Martijn Dekker's "u+m"
    version. (The latter has less bugs and works much more reliable.)
    It's just my recent switch that made me notice that in his branch
    there's no 'alarm' available any more.

    Janis


    I was mistaken; alarm is in the att-ksh93 pkgsrc package, it's just an undocumented built-in, apparently because D. Korn felt it it didn't
    function consistently. My brief experiments earlier resulted in several
    hung sessions. It's an interesting idea though.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John-Paul Stewart@21:1/5 to Arti F. Idiot on Mon Mar 18 16:27:14 2024
    On 2024-03-18 10:14 a.m., Arti F. Idiot wrote:

    I think several OSes have a tool called 'progress' which sort of
    functions as you've described; NetBSD does natively. 

    Careful, though. On Linux systems it is unlikely to be installed by
    default. And even if it is installed, it's likely to be a very
    different 'progress' program than the NetBSD one:

    https://github.com/Xfennec/progress

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Keith Thompson on Mon Mar 25 04:49:06 2024
    On Mon, 18 Mar 2024 12:39:51 -0700, Keith Thompson wrote:

    Scheduled commands run only while the shell is waiting at a prompt for
    input.

    I wonder why shells don’t make use of poll(2) to run things asynchronously
    to command input.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)