On Mon, Jul 02, 2012, Michael O'Donnell wrote about "Re: [ctwm] SIGSEGV patch":
>    Note that I was usually able to recover my entire X session
>    and continue without harm if I could manage to launch a
>    new instance of CTWM from the console or an SSH session.
>    Until I patched my CTWM I actually had a shell loop right
>    inside my .xsession file that would automatically relaunch
>    CTWM when it crashed, so I was able to live with it for
>    several years before finally getting fed up and fixing it!

I too have noticed that ctwm crashes for me about once a month or so,
but I could never figure out why. So like you, I ran ctwm in a loop ;-)
Actually, I was worried about endless quick restarts in case ctwm
couldn't start at all, so I wrote a script called "respawn", which
you run as "respawn ctwm":

#!/bin/sh
# Run a given program which is expected to be very long lived (e.g., a
# window manager), and when it stops, automatically restart it.
#
# To prevent rapid endless loops of failures, if the command finished
# quickly (less than an amount of time known as "goodtime"), it will not
# be restarted immediately but rather a bit of time is waited, and this
# time is made longer and longer (exponential backoff).

retry=1 # initial number of seconds to wait between a retry
goodtime=120 # amount of time the program runs that seems not too low to
worry

while :
do
        start=`date +%s`
        "$@"
        end=`date +%s`
        elapsed=`expr $end - $start`
        if [ $elapsed -gt $goodtime ]
        then
                # command didn't finish too quickly, doesn't appear to
                # be a repeating error.
                retry=1
        else
                retry=`expr $retry '*' 2`
        fi
        echo sleeping $retry
        sleep $retry
done


-- 
Nadav Har'El                        |     Thursday, Jul 5 2012, 15 Tammuz 5772
[email protected]             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |Help Wanted: Telepath. You know where to
http://nadav.harel.org.il           |apply.

Reply via email to