<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 10, 2019 at 7:31 PM Stephen Worthington <<a href="mailto:stephen_agent@jsw.gen.nz">stephen_agent@jsw.gen.nz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sun, 10 Mar 2019 14:59:19 -0700, you wrote:<br>
<br>
>I added a 10 second delay and the problem is gone, no duplicate instances<br>
>of myth. Maybe 3 seconds would work but definitely a race condition. Other<br>
>than the delay, the code is the same as original.<br>
><br>
>In fairness to the code, my test is not real life. Typically if I were to<br>
>do a CTRL-ALT-BS it would be because myth was frozen or missing. I don't<br>
>know that I ever did a CTRL-ALT-BS just as a test with Myth running. The<br>
>timing might be different and the service might be killed faster if it is<br>
>actually frozen. Or maybe I am wrong and this really is an issue. Either<br>
>way, it should not keep piling on instances of mythfrontend. But at least<br>
>I think we know what is going on now.<br>
><br>
>Allen<br>
<br>
Using a delay to fix a race condition is usually a bad idea -<br>
something happens which changes the timing, such as a bit of swapping<br>
going on, and then the problem is back again.<br>
<br>
Unfortunately, mythfrontend does die quite often for me. The usual<br>
cause is playing a downloaded video file. I have quite a few that it<br>
can not handle, and either it dies, or locks up and I have to kill it.<br>
Some of the deaths leave behind "assert failed" messages. But if you<br>
do not normally play such files, then mythfrontend can be very<br>
reliable and not need the wrapper script.<br>
<br>
It looks like the wrapper script needs to be able to detect that the<br>
script itself is still running and to exit if it can see another copy<br>
of itself. This should work to do that:<br>
<br>
pid=$(ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' | grep<br>
-v grep | awk '{print $2}')<br>
if [ ${#pid} -ne 0 ]; then<br>
exit 0<br>
fi<br>
_______________________________________________<br><br></blockquote><div>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.</div><div><br></div><div><b>dad@NewMyth:~$ ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' | grep -v grep</b></div><div><b>dad 2310 1 0 09:17 ? 00:00:00 /bin/sh /usr/bin/mythfrontend --service</b></div><div><b>dad 2605 1 0 09:17 ? 00:00:00 /bin/sh /usr/bin/mythfrontend --service</b></div><div><b>dad 2961 2939 0 09:17 ? 00:00:00 /bin/sh /usr/bin/mythfrontend --service</b></div><div><b><br></b></div><div>And</div><div><b><br></b></div><div><div><b>dad@NewMyth:~$ ps -ef | grep '/bin/sh /usr/bin/mythfrontend --service' | grep -v grep | awk '{print $2}'</b></div><div><b>2310</b></div><div><b>2605</b></div><div><b>2961</b></div><div><br></div><div>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.</div><div><br></div><div>I wish to thank both Stephen and Ian for your help.</div><div><br></div><div>Allen</div><div style="font-weight:bold"><br></div></div><div><b><br></b></div><div><b><br></b></div><div><br></div><div><br></div><div> </div></div></div></div></div>