[mythtv-users] CTRL-ALT-BACKSPACE -> multiple instances of mythfrontend

Allen Edwards allen.p.edwards at gmail.com
Tue Mar 12 14:30:49 UTC 2019


On Tue, Mar 12, 2019 at 3:53 AM Stephen Worthington <
stephen_agent at jsw.gen.nz> wrote:

> On Mon, 11 Mar 2019 09:41:08 -0700, you wrote:
>
> >On Sun, Mar 10, 2019 at 7:31 PM Stephen Worthington <
> >stephen_agent at jsw.gen.nz> wrote:
> >
> >> On Sun, 10 Mar 2019 14:59:19 -0700, you wrote:
> >>
> >> >I added a 10 second delay and the problem is gone, no duplicate
> instances
> >> >of myth. Maybe 3 seconds would work but definitely a race condition.
> >> Other
> >> >than the delay, the code is the same as original.
> >> >
> >> >In fairness to the code, my test is not real life.  Typically if I
> were to
> >> >do a CTRL-ALT-BS it would be because myth was frozen or missing. I
> don't
> >> >know that I ever did a CTRL-ALT-BS just as a test with Myth running.
> The
> >> >timing might be different and the service might be killed faster if it
> is
> >> >actually frozen. Or maybe I am wrong and this really is an issue.
> Either
> >> >way, it should not keep piling on instances of mythfrontend.  But at
> least
> >> >I think we know what is going on now.
> >> >
> >> >Allen
> >>
> >> Using a delay to fix a race condition is usually a bad idea -
> >> something happens which changes the timing, such as a bit of swapping
> >> going on, and then the problem is back again.
> >>
> >> Unfortunately, mythfrontend does die quite often for me.  The usual
> >> cause is playing a downloaded video file.  I have quite a few that it
> >> can not handle, and either it dies, or locks up and I have to kill it.
> >> Some of the deaths leave behind "assert failed" messages.  But if you
> >> do not normally play such files, then mythfrontend can be very
> >> reliable and not need the wrapper script.
> >>
> >> It looks like the wrapper script needs to be able to detect that the
> >> script itself is still running and to exit if it can see another copy
> >> of itself.  This should work to do that:
> >>
> >> pid=$(ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' | grep
> >> -v grep | awk '{print $2}')
> >> if [ ${#pid} -ne 0 ]; then
> >>     exit 0
> >> fi
> >> _______________________________________________
> >>
> >> I do not understand why this does not work but I am no script expert so
> I
> >am not sure what exactly is going on with ${#pid} and how that relates to
> >the initial pid. Perhaps there is a $ missing or misplaced on the first
> >line?  I did run some tests.
> >
> >*dad at NewMyth:~$ ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' |
> >grep -v grep*
> >*dad       2310     1  0 09:17 ?        00:00:00 /bin/sh
> >/usr/bin/mythfrontend --service*
> >*dad       2605     1  0 09:17 ?        00:00:00 /bin/sh
> >/usr/bin/mythfrontend --service*
> >*dad       2961  2939  0 09:17 ?        00:00:00 /bin/sh
> >/usr/bin/mythfrontend --service*
> >
> >And
> >
> >*dad at NewMyth:~$ ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' |
> >grep -v grep | awk '{print $2}'*
> >*2310*
> >*2605*
> >*2961*
> >
> >For now I will just run mythfrontend without the --service option.  That
> >should be fine for my needs. I am still willing to troubleshoot this if
> you
> >think that would be useful so let me know.
> >
> >I wish to thank both Stephen and Ian for your help.
> >
> >Allen
>
> $(#pid} is the number of characters in the $pid string.  If there are
> any copies of mythfrontend running, then the $pid string should be a
> list of the PIDs for those copies (actually, a list of the PIDs of the
> bash tasks running those copies of the scripts).  So if there are no
> other copies of mythfrontend running, $pid should be an empty string,
> and ${#pid} should be 0.  I tested it using this script (t1.sh):
>
> #!/bin/bash
> pid=$(ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' | grep
> -v grep | awk '{print $2}')
> echo $pid
> echo ${#pid}
> if [ ${#pid} -ne 0 ]; then
>     echo "pid != 0"
> fi
>
> On my MythTV box, it displays the "pid != 0" string whenever it finds
> a copy of the mythfrontend script running.  If I add an extraneous
> character to the grep string (eg an extra d on the end of
> "mythfrontend", it gets no matches and continues on to the end of the
> script without doing the echo.
> _______________________________________________
>
> I have not tested it yet but I think the problem I had was I copied and
pasted the script you wrote without changes and the word wrap that put a
return between grep and -v grep would generate an error.  I tested the
components of it but put it all on one line when I did that and did not
realize that the script would not run as posted.  Pretty stupid mistake on
my part.

Your script as it came across the email
pid=$(ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' | grep
-v grep | awk '{print $2}')
if [ ${#pid} -ne 0 ]; then
    exit 0
fi

A corrected version
pid=$(ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' | grep -v
grep | awk '{print $2}')
if [ ${#pid} -ne 0 ]; then
    exit 0
fi

I would be shocked if this did not work but can't test it now.

Allen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mythtv.org/pipermail/mythtv-users/attachments/20190312/ab130c41/attachment.html>


More information about the mythtv-users mailing list